mirror of
https://bitbucket.org/Mattrixwv/octavefunctions.git
synced 2025-12-06 18:53:57 -05:00
Added check for the correct number of variables and added a few comments
This commit is contained in:
15
NewNewton.m
15
NewNewton.m
@@ -4,17 +4,24 @@ function [xList, errorList] = NewNewton (f, startingValue, errorAllowed)
|
||||
%This function computes the root of a function using the modified Newton's method
|
||||
%
|
||||
|
||||
%Make sure the number of arguments is correct
|
||||
if(narginchk(3,3))
|
||||
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;
|
||||
fp = diff(f);
|
||||
fpp = diff(fp);
|
||||
%Variables
|
||||
oldAnswer = startingValue;
|
||||
newAnswer = 0;
|
||||
currentError = errorAllowed + 1;
|
||||
cnt = 1;
|
||||
maxIt = 50;
|
||||
fp = diff(f);
|
||||
fpp = diff(fp);
|
||||
|
||||
|
||||
%Loop until you find an answer within error or you reach the maximum number of itterations
|
||||
while((currentError >= errorAllowed) && (cnt < maxIt))
|
||||
newAnswer = oldAnswer - ((double(subs(f,oldAnswer)) * double(subs(fp,oldAnswer)))/(double(subs(fp,oldAnswer))^2 - (double(subs(f,oldAnswer)) * double(subs(fpp,oldAnswer)))));
|
||||
currentError = abs(newAnswer - oldAnswer);
|
||||
|
||||
Reference in New Issue
Block a user