Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
549 views

Secant Method MATLAB Code

This MATLAB function uses the secant method to find the root of a function defined in a separate M-file. It takes initial guesses, maximum iterations, and tolerance as inputs and iterates until convergence is reached or the maximum number of iterations is exceeded, updating the guesses at each step based on the secant slope between previous points.

Uploaded by

Sanjeet Sahoo
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
549 views

Secant Method MATLAB Code

This MATLAB function uses the secant method to find the root of a function defined in a separate M-file. It takes initial guesses, maximum iterations, and tolerance as inputs and iterates until convergence is reached or the maximum number of iterations is exceeded, updating the guesses at each step based on the secant slope between previous points.

Uploaded by

Sanjeet Sahoo
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

9/8/17 5:21 PM E:\Matlab\CL249\Secant_SSJ.

m 1 of 1

function x = Secant_SSJ(x01,x02,iter_max,error_tol)
% Solve fx = 0 system using Secant method
% Created by Sujit Jogwar on July 31, 2017
% inputs
% x01: initial guess 1
% x02: initial guess 2
% iter_max: maximum allowed iterations
% error_tol: tolerance value for error
% user enters the function f(x) in fun_value.m file

for i = 1:iter_max
f1 = fun_value(x01);
f2 = fun_value(x02);
slope = (f2-f1)/(x02-x01);
x = x02 - f2/slope;
% check convergence
if norm(fun_value(x)) < error_tol
disp(['Convergence achieved in ' num2str(i) ' iterations']);
break; % stops iterations
else
% check if max iterations have reached
if i == iter_max
disp('Maximum iterations reached without satisfying convergence
criteria');
else
% proceed to the next iteration with updated initial
% condition
x01 = x02;
x02 = x;
end
end
end

You might also like