0

I want to find a function $g$ such that it is a contraction and such that finding its fixed point is the same as finding the zeros of $f(x)=x^3+x-3$ because I have implemented the fixed-point iteration method in MATLAB as follows

function fixedpointt(x0)
%example of fixed point iteration

%zeros of f(x)=x^3+x-3

    tol=10^-6; % tolerance
    itmax=1000; % max number of iterations
    itnum=0; % iterations counter

    %x0=10; % initial condition
    disp([itnum,x0])
    x1=g3(x0);
    itnum=itnum+1;
    disp([itnum,x1,abs((x0-x1)/x0)])

    while abs((x0-x1)/x0)>tol && itnum<itmax
        x0=x1;
        x1=g3(x0);
        itnum=itnum+1;
        disp([itnum,x1,abs((x0-x1)/x0)])
    end

end



function y=g3(x)
    y=3/(x^2+1);
end

The thing is that I figured out $g(x)=\frac{3}{x^2+1}$ but it didn't worked, so Can someone help me to find a function that fits with the above characteristics please?

Thanks a lot in advance.

user162343
  • 3,245

1 Answers1

0

Maybe Newton's method will work. At least it did with starting points 1, or -5. It would be to map $x$ to $x-f(x)/f'(x)$ which is $(2x^3+3)/(3x^2+1).$ It seems you may have been going for this, as your formula has the same denominator but in yours the numerator is the constant 3.

With initial value 1 it took only 4 steps to stabilize to about 1.2134116. With initial value -5 it took more steps, 7 o4 8, but still arrived at the same thing.

coffeemath
  • 29,884
  • 2
  • 31
  • 52
  • Let me check it and If I have a question can I let you know ? – user162343 Sep 21 '15 at 00:12
  • Yes, let me know if question (will reply eventually) – coffeemath Sep 21 '15 at 00:25
  • Well I think your function was good but when I run my code it gives me -1.144713980133249e+00 and that is not what is needed :) Thanks :) – user162343 Sep 21 '15 at 00:58
  • On the tenth iteration it has settled down to 1.213411663. Here are the numbers, with the first being 10 as in your code. I rounded here to four decimals but more for the last few: 10, 6.6544, 4.4255, 2.9512, 2.0055, 1.4642, 1.2484, 1.2142, 1.2134120, 1.213411663, 1.21341163. Given the function is increasing and second derivative positive, if one starts anywhere to the right of the zero of the function Newton's method guarantees the iterations go monotonically down toward the zero., I don't see how you ever got a negative number. – coffeemath Sep 21 '15 at 09:19
  • Maybe your implementation didn't keep enough decimals between iterations, and maybe "double precision" would make it work right. [I'm not an expert on computer code languages, and certainly one doesn't want to do it all in exact fractions,] – coffeemath Sep 21 '15 at 09:33
  • Well what I did is only substitute y=g(x) ,y=(x^3+x-3)/(3*x^2+1) in the last part of my code and that is what it gives me :( what is wrong then ? – user162343 Sep 21 '15 at 13:35