For this method it is necessary to convert f(x)=0 into an equitable expression of the form x=g(x), in doing this we will be plotting the line y=x and the curve given by g(x), for the method we first choose the initial x0, this will be evaluated in g(x) giving a new x1 since x=g(x), this new x1 is evaluated in the original function to see if we already find the root f(x)=0, if it is not the case, with the new x1 we repeat the process evaluating it in g(x) and finding the new x2, and so on until we find the expected value.
PSEUDOCODE
Input: a, g(x), tolerance.
Error = Tolerance + 1
i=0
While Error > Tolerance
pn= f(a)
Error = ABS( pn – a)
a=pn
i=i+1
print: i,a,pn,error
End
End
CODE
clc;clear
f=input('Enter function with x clear: ','s');
f=inline(f);
a=input('Enter initial value: ');
tol=input('Enter tolerance: ');
e=tol+1;
i=0;
while e>tol
pn=f(a);
e=abs(pn-a);
a=pn;
i=i+1;
fprintf('iter: %2i\t a= %f\t pn= %f\t e= %f\n',i,a,pn,e)
end