Question

Operators and Symbols Style Cipboard CE 2010 Spring 2010 Secant Root Finding Method Secant , N-0 for i e 1..mar Error Functio

we are having trouble getting the secant to become defined as well as the a becoming defined. Any help is greatly appreciated!

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


%Matlab code for Secant method clear all close all %Function for which root have to find f-e(x) 20 pi-50x+25 sin(x)i fprintf용옹옹융융옹옹옹옹옹옹옹옹옹옹옹옹옹융융융옹융융용융융융용융융융88응용888888号%88응용88응용88응용88 For the function f(x)= @(x)20+pi-50*x+25 *sin(x) Has reached maxim

%Matlab code for Secant method
clear all
close all
%Function for which root have to find
f=@(x) 20*pi-50*x+25*sin(x);
fprintf('For the function f(x)= ')
disp(f)

%finding root using Secant Method
a=[1 2];    %initial guess
e=0.000001; %error convergence
max=5;      %Maximum iterations

%Root using Secant method
[root]=secant_method(f, a, e, max);

fprintf('\tThe root for this function is %f\n',root)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Matlab function for Secant Method
function [root]=secant_method(f, a, e, max)

    %a= vector of two initial guess
    %e= error tollerence
    %max= maximum number of iterations

    %x0 and x1 values for two initial guess
    x0=a(1); x1=a(2);
    %checking wheather function values for two initial guesses are same
    if f(x0)==f(x1)
        msg = 'Function values are identical at initial guesses.';
        error(msg);
    end
    %loop for Secant iterations
    k=0;
    for i=1:max
        k=k+1;
        xx=double(x1-(f(x1)*abs((x1-x0)/(f(x1)-f(x0)))));
        x0=x1;
        x1=xx;
        if(abs(xx-x0)<=e)
            break
        end

    end
    root=xx;
    %If maximum iteration reached
    if i==max
        fprintf('Has reached maximum iteration steps allowed.\n')
    end
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Add a comment
Know the answer?
Add Answer to:
we are having trouble getting the secant to become defined as well as the a becoming defined. Any help is greatly appreciated! Operators and Symbols Style Cipboard CE 2010 Spring 2010 Secant Root...
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