mirror of
https://bitbucket.org/Mattrixwv/octavefunctions.git
synced 2026-02-04 04:02:32 -05:00
Added new files for Numerical Analysis
This commit is contained in:
30
Secant.m
Normal file
30
Secant.m
Normal file
@@ -0,0 +1,30 @@
|
||||
function [xList, errorList] = Secant(f, p0, p1, errorAllowed)
|
||||
%
|
||||
%Secant(f, p0, p1, errorAllowed)
|
||||
%This function find the root of a function using the Secant Method
|
||||
%
|
||||
|
||||
pkg load symbolic;
|
||||
warning('off','OctSymPy:sym:rationalapprox');
|
||||
maxIt = 50;
|
||||
cnt = 2;
|
||||
q0 = double(subs(f,p0));
|
||||
q1 = double(subs(f,p1));
|
||||
currentError = errorAllowed + 1;
|
||||
p = 0;
|
||||
|
||||
|
||||
while((cnt <= maxIt) && (currentError >= errorAllowed))
|
||||
p = p1 - (q1 * (p1 - p0))/(q1 - q0);
|
||||
currentError = abs(p - p1);
|
||||
%Add the x and error values to memory
|
||||
xList(end+1) = p;
|
||||
errorList(end+1) = currentError;
|
||||
%Setup for the next run
|
||||
++cnt;
|
||||
p0 = p1;
|
||||
q0 = q1;
|
||||
p1 = p;
|
||||
q1 = double(subs(f,p));
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user