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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!