%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %STUDENTS OF 412 ARE ENTITLED TO USE A VARIATION OF THIS FILE FOR %THEIR ASSIGNMENT. IF YOU DO THAT, REPORT THAT FACT ON THE %ASSIGNMENT (WRITE : `I USED THE CODE AT CLASS ACCOUNT AS MY BASE CODE') %YOU MAY WISH, HOWEVER, TO WRITE SOMETHING A BIT MORE SOPHISTICATED %++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %in this file, we try to solve the equation x^3=sin(x) %using four different fixed point algorithms. %rat is the (estimated) ratio between the current error and the previous one. %only one iteration is performed. %before you use this file, type `n=1'. This will initialize the %parameters in the code, and will also keep a counter on the number %of iterations. the value of rat after one iteration is meaningless. %note that the solution is around .9 if n==1 k=4 ; % k is the number of different fixed point algorithms you run % it is 4 in the current code. if you add more, change k x=ones(1,k); error=ones(1,k); a=3-cos(1); end % we store in x the old value of x, and in y new value of x, i.e., y=g(x) %when we are done, we overwrite x by y (for the sake of the new iteration) %alternatively, you can generate a vector where all the iterative values y(1)=sin(x(1))^(1/3); y(2)=sin(x(2))/x(2)^2; y(3)=x(3)-(x(3)^3-sin(x(3))); y(4)=x(4)-(x(4)^3-sin(x(4)))/a; %y(5)=asin(x(5)^3); %try that if you wish. do not forget to change k then %add a few more choices if you wish %e.g., try to see how Newton's method outperform the competition rat=(y-x)./error %that's it. we now update error and x (anticipating another iteration) error=y-x; x=y, n=n+1;