Added check for the correct number of variables and added a few comments

This commit is contained in:
2018-09-22 16:19:44 -04:00
parent 3b669a2979
commit 3f00730c9f
6 changed files with 60 additions and 13 deletions

View File

@@ -4,15 +4,24 @@ function [xList, errorList] = FalsePosition(f, p0, p1, errorAllowed)
%This function finds the root of a function using the method of False Position
%
%Make sure the number of arguments is correct
if(narginchk(4, 4))
error('That is an incorrect number of arguments')
end
%A few necesary before we begin
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));
p = 0;
q = 0;
currentError = errorAllowed + 1;
%Loop until you find a value within the 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);