Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data And Databases

Authors: Jeff Mapua

1st Edition

1978502257, 978-1978502253

More Books

Students also viewed these Databases questions

Question

Identify the primary causes of conflict in the work setting.

Answered: 1 week ago

Question

Answered: 1 week ago

Answered: 1 week ago

Question

What are Decision Trees?

Answered: 1 week ago

Question

What is meant by the Term Glass Ceiling?

Answered: 1 week ago