Numerical Methods and Analysis: College of Engineering Mechatronics Department
Numerical Methods and Analysis: College of Engineering Mechatronics Department
Mechatronics Department
Report No. 2
2. Theory:
Write a MATLAB code for the following Secant method algorithm:
1. Start with syms x and write the function f
2. Define values of x0, x1 and es
% Here x0 and x1 are the two initial guesses
% es is the stopping criteria, absolute error or the
desired % degree of accuracy
3. while (1) % Initiate an infinite loop
Compute x2 = x1– (f(x1) * ( x1– x0)) / (f(x1) –
f(x0))
Compute ea = abs( (x2 – x1)/x2 )*100
Test for accuracy of x2
if es > ea
break;
else
x0=x1;
x1=x2;
end
end % end of infinite loop
4. Display the required root as x2.
Stop
3.Experimental Procedure and apparatus
Iteratio
xi+1 ea
n
1 -0.5137
2 -0.6100 0.044
3 -0.6518 0.158
4 -0.6588 0.085
5 -0.6593 0.010
6 -0.6593 0.001
6
Exercise 2: Use secant method to find the root of x −x−1 , take x0=1 and x1=1.5.,
take eps=0.0001
Iteratio
xi+1 ea
n
1 -8.8906
2 -0.7062
3 -0.4645
4 0.1321
5 -0.0165
6 -0.0005
Conclusion:
Secant method was learned, we were able to solve a lot of different problems using mat lab
and the effect of the roots were obvious to us.