Question
This Matlab code keeps giving me the error flag previously appeared to be used as a function or command, conflicting with its use here as
This Matlab code keeps giving me the error ""flag" previously appeared to be used as a function or command, conflicting with its use here as the name of a variable.A possible cause of this error is that you forgot to initialize the variable, or you have initialized it implicitly using load or eval." Can someone help me fix this?
Original Assignment:
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.
(My Code)
function y = secant(f,a,b,max)
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)) > max 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;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started