test 1 solve it Write a syntactically correct Matlab progra

test 1 , solve it

Write a syntactically correct Matlab program to implement the secant method to find a root of f: R rightarrow R defined by f(x) = e^x - 2.

Solution

%% It will take function and initial value as the input of function. % We would require to run it in command window as % secant (@(x)(e^x - 2),2,3.8,0.001) % where (e^x - 2) is function, [2,3] initial values and 0.001 is maximum % error tolerable. 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;
test 1 , solve it Write a syntactically correct Matlab program to implement the secant method to find a root of f: R rightarrow R defined by f(x) = e^x - 2.Solu

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site