Could you create me a secant code in Matlab program? That's I can keep it and...

Free

50.1K

Verified Solution

Question

Physics

Could you create me a secant code in Matlab program? That's I cankeep it and use it for any time?

Answer & Explanation Solved by verified expert
3.7 Ratings (350 Votes)

In this program for secant method in Matlab, first the equation to be solved is defined and assigned with a variable ‘a’ using inline( ) library function. Then, the approximate guess values and desired tolerance of error are entered to the program, following the MATLAB syntax.

7

8

9

10

11

12

13

14

15

16

17

18

19

% Secant Method in MATLAB

a=input('Enter function:','s');

f=inline(a)

x(1)=input('Enter first point of guess interval: ');

x(2)=input('Enter second point of guess interval: ');

n=input('Enter allowed Error in calculation: ');

iteration=0;

for i=3:1000

   x(i) = x(i-1) - (f(x(i-1)))*((x(i-1) - x(i-2))/(f(x(i-1)) - f(x(i-2))));

    iteration=iteration+1;

    if abs((x(i)-x(i-1))/x(i))*100

        root=x(i)

        iteration=iteration

        break

    end

end

please rate it up thanks :)


Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students