BONGOS
BONGOS
BONGOS
FACULTY OF ENGINEERING
As expected, the curve shows one crossing between 2 and 3 , so we take 2 as our first
approximation,
The commands were ran as below;
f=@(x) x.^2-5;
x0=2;
x1=3;
tolx=1e-10;
tic
for i=1:30
x=(x0+x1)/2;
if f(x)*f(x1)<0
x0 = x;
else
x1 = x;
end
err = abs(x0-x1);
if err<tolx
break
end
end
toc
fprintf('the root is : %f\nthe number of iterations are: %d\n',x,i)
this was the result after running the command.
Elapsed time is 0.010359 seconds.
the root is : 2.236068
the number of iterations are: 30
fprintf('iteration=%d\tx0=%f\tx=%f\n',i,x0,x1)
if abs(f(x2)-f(x1))>=tolx
x0=x1;
x1=x2;
else
break
end
end
toc
results
iteration=1 x0=2.000000 x=3.000000
iteration=2 x0=3.000000 x=2.200000
iteration=3 x0=2.200000 x=2.230769
iteration=4 x0=2.230769 x=2.236111
iteration=5 x0=2.236111 x=2.236068
Elapsed time is 0.020749 seconds
CONCLUSION
Based on our results and discussions, we concluded that the secant method is formally the most
effective of the methods we have considered here in the study. This is to the fact that it has a
converging rate close to that of newton Raphson method but requires only a single function
evaluation per iteration. We also concluded that though the conversion of bisection is certain, its
rate of convergence is too slow and as such it is difficult to extend to use for systems of equation.
Therefore we would recommend someone to use the secant method because it requires only
evaluation of the function