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'])
5
  • I believe it works, I fixed a typo. I am still uncertain if this is acceptable to manipulate the original equation as I did. Commented Sep 17, 2019 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? Commented Sep 17, 2019 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. Commented Sep 17, 2019 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, which can be written as a fixed point iteration. Commented Sep 17, 2019 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. Commented Sep 18, 2019 at 3:50

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.