mirror of
https://bitbucket.org/Mattrixwv/octavefunctions.git
synced 2025-12-06 18:53:57 -05:00
Added new files for Numerical Analysis
This commit is contained in:
25
NewNewton.m
Normal file
25
NewNewton.m
Normal 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
|
||||
Reference in New Issue
Block a user