Question

Write a line search Secant methods for solving f(x)=0 and implement the algorithms for solving the...

Write a line search Secant methods for solving f(x)=0 and implement the algorithms for solving the x^2-1=0 in Matlab Programming.

0 0
Add a comment Improve this question Transcribed image text
Answer #1


%%Matlab code for secant method for finding root clear all close all %function for which root have to find f-e (x) x.*2-1; ti

%%Matlab code for Secant method for finding root
clear all
close all
%function for which root have to find
f=@(x) x.^2-1;
%initial guess
x0=0;x1=2;
[root,count]=secant_method(f,x0,x1);
%displaying the function
fprintf('For the function f(x)=\n')
disp(f)
fprintf('The root of the function using Secant method is %f.\n',root)


%Matlab function for Secant Method
function [root,count]=secant_method(fun,x0,x1)
%f(x1) should be positive
%f(x0) should be negative
k=10; count=0;
while k>10^-6
    count=count+1;
    xx=double(x1-(fun(x1)*abs((x1-x0)/(fun(x1)-fun(x0)))));
    x0=x1;
    x1=xx;
    k=abs(fun(xx));
end
root=xx;
end

%%%%%%%%%%% End of Code %%%%%%%%%%

Add a comment
Know the answer?
Add Answer to:
Write a line search Secant methods for solving f(x)=0 and implement the algorithms for solving the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT