Added new files for Numerical Analysis

This commit is contained in:
2018-09-22 15:27:54 -04:00
parent 52997050f5
commit 3b669a2979
7 changed files with 197 additions and 0 deletions

25
NewNewton.m Normal file
View File

@@ -0,0 +1,25 @@
function [xList, errorList] = NewNewton (f, startingValue, errorAllowed)
%
%NewNewton (f, startingValue, errorAllowed)
%This function computes the root of a function using the modified Newton's method
%
pkg load symbolic;
warning('off','OctSymPy:sym:rationalapprox');
oldAnswer = startingValue;
newAnswer = 0;
currentError = errorAllowed + 1;
cnt = 1;
maxIt = 50;
fp = diff(f);
fpp = diff(fp);
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);
xList(end+1) = newAnswer;
errorList(end+1) = currentError;
oldAnswer = newAnswer;
end
end