mirror of
https://bitbucket.org/Mattrixwv/octavefunctions.git
synced 2026-02-04 04:02:32 -05:00
Added check for the correct number of variables and added a few comments
This commit is contained in:
9
Secant.m
9
Secant.m
@@ -4,16 +4,23 @@ function [xList, errorList] = Secant(f, p0, p1, errorAllowed)
|
||||
%This function find the root of a function using the Secant Method
|
||||
%
|
||||
|
||||
%Make sure the number of arguments is correct
|
||||
if(narginchk(4,4))
|
||||
error('That is an incorrect number of arguments')
|
||||
end
|
||||
%A few necesary things before we get started
|
||||
pkg load symbolic;
|
||||
warning('off','OctSymPy:sym:rationalapprox');
|
||||
%Constant variables
|
||||
maxIt = 50;
|
||||
%Variables
|
||||
cnt = 2;
|
||||
q0 = double(subs(f,p0));
|
||||
q1 = double(subs(f,p1));
|
||||
currentError = errorAllowed + 1;
|
||||
p = 0;
|
||||
|
||||
|
||||
%Loop until you find an answer within error or you reach the maximum number of itterations
|
||||
while((cnt <= maxIt) && (currentError >= errorAllowed))
|
||||
p = p1 - (q1 * (p1 - p0))/(q1 - q0);
|
||||
currentError = abs(p - p1);
|
||||
|
||||
Reference in New Issue
Block a user