Write a matlab program to implement the secant root finding method in matlab. Th
ID: 3690347 • Letter: W
Question
Write a matlab program to implement the secant root finding method in matlab.
The function name should be Secant and it should take the equation as input whoes root has to be found and the two initial values of a and b and maximum tolerable error.
Consider the following example:
Your code should generate the following:
>> secantAssg5(@(x)(x^4+x^2+x+10),2,3,0.0001)
Xn-1 f(Xn-1) Xn f(Xn) Xn+1 f(Xn+1)
2.0000 32.0000 3.0000 103.0000 1.5493 19.7111
…..
…..
…..
Root is x = 0.13952
ans =
0.1395
Explanation / Answer
PFB the MATLAB code function y = secant(f,a,b,maxerr) c = (a*f(b) - b*f(a))/(f(b) - f(a)); disp(' Xn-1 f(Xn-1) Xn f(Xn) Xn+1 f(Xn+1)'); disp([a f(a) b f(b) c f(c)]); while abs(f(c)) > maxerr a = b; b = c; c = (a*f(b) - b*f(a))/(f(b) - f(a)); disp([a f(a) b f(b) c f(c)]); flag = flag + 1; if(flag == 100) break; end end display(['Root is x = ' num2str(c)]); y = c;
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.