

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This is Matlab code for Secant Method. Just copy and paste this code into an m-file and run. It works perfect.
Typology: Study Guides, Projects, Research
1 / 2
This page cannot be seen from the preview
Don't miss anything!


On special offer
% Find the roots of using Secant Method % func --> function is taken by user % like sin(x) or x^2 + x - 1 or any other but use the same format % i.e. use paranthesis as used above with 'x' for sin, cos,... etc % and spacing between '+' or '-' operation % a --> Xn- % b --> Xn % c --> Xn+ % maxerr --> Maximum Error in Root syms x; func = input('Enter Function in terms of x: '); a = input('Ener Lower Limit: '); b = input('Ener Upper Limit: '); maxerr = input('Enter Maximum Error: '); f = inline(func); c = (af(b) - bf(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 b = a; a = c; c = (af(b) - bf(a))/(f(b) - f(a)); disp([a f(a) b f(b) c f(c)]); end display(['Root is x =' num2str(c)]); % ========= % % Thank you % ========= %