0

I am not sure if I have come across a trick question or not, but I am coding a fixed point recursion to find root for a given equation. To me, it seems like I have the answer right off the bat, but I am still trying to determine how to manipulate the equation to make it work for my algorithm.

The equation is f(x) = sqrt(x) - 1.1 I thought I am suppose to manipulate to isolate an x, but this is just giving me the answer. Is there another way to manipulate it to make it work for algorithm?

Here is my code:

% FIXED POINT ITERATION
% function = sqrt(x) - 1.1
% error <= 1.e-8
% sqrt(x) = 1.1
% x = 1.1^2

clear;clc;format('long','g')
i = 1;
x(i) = 0;
error(i) = 9999;

while error(i) >= 1.e-8
    %% NOT WORKING WITH THIS MANIPULATION
    x(i+1) = sqrt(x(i))*1.1; 
    error(i+1) = abs(x(i+1)-x(i)); %abs((((x(i+1)-x(i))/(x(i+1)))*100));
    i = i +1;
end
disp('            root                 error(%)');
disp([x',error'])
John McFarlane
  • 4,081
  • 2
  • 28
  • 33
  • I believe it works, I fixed a typo. I am still uncertain if this is acceptable to manipulate the original equation as I did. – PattyWatty27 Sep 17 '19 at 21:21
  • This code gives `x=0` as the solution, which of course is wrong, you expect `x=1.21`. In any case, I don't understand the question. Are you asking if your instructor will accept your solution? Shouldn't you ask your instructor that? How are we supposed to know what she wants from you? – Cris Luengo Sep 17 '19 at 21:31
  • @CrisLuengo No. I am unsure if the way I manipulated the original equation is acceptable for fixed point method and I found a couple errors in code myself that after fixing them, it works now. – PattyWatty27 Sep 17 '19 at 21:41
  • Obviously it is not an acceptable way to manipulate the original equation -- you get the wrong result. The fixed point of the equation is not its root. I think you might be looking for [Newton's method](https://en.wikipedia.org/wiki/Fixed-point_iteration#Applications), which can be written as a fixed point iteration. – Cris Luengo Sep 17 '19 at 21:49
  • Your manipulations are correct, and the fixed-point iteration converges for a non-zero value. Try `2.0`. The problem with `0` as a guess is that then the fixed-point simply maps to itself; the sequence, from that guess, is all zeros and never converges. – TroyHaskin Sep 18 '19 at 03:50

0 Answers0