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:
13
Mullers.m
13
Mullers.m
@@ -4,17 +4,25 @@ function [xList, functionValueList] = Mullers(f, p0, p1, p2, errorAllowed)
|
||||
%This function finds the root of a function using Muller's Method
|
||||
%
|
||||
|
||||
%Make sure the number of arguments is correct
|
||||
if(narginchk(5,5))
|
||||
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
|
||||
h1 = p1 - p0;
|
||||
h2 = p2 - p1;
|
||||
s1 = (double(subs(f,p1)) - double(subs(f,p0))) / h1;
|
||||
s2 = (double(subs(f,p2)) - double(subs(f,p2))) / h2;
|
||||
d = (s2 - s1) / (h2 + h1);
|
||||
cnt = 2;
|
||||
maxIt = 50;
|
||||
|
||||
%Loop until you reach the maximum number of itterations
|
||||
%If you find an answer within error it will return
|
||||
while(cnt < maxIt)
|
||||
b = s2 + h2 * d;
|
||||
D = (b^2 - (4 * double(subs(f,p2)) * d))^(1/2);
|
||||
@@ -27,6 +35,7 @@ function [xList, functionValueList] = Mullers(f, p0, p1, p2, errorAllowed)
|
||||
p = p2 + h;
|
||||
xList(end+1) = p;
|
||||
functionValueList(end+1) = double(subs(f,p));
|
||||
%Exit the function if you get an answer within error
|
||||
if(abs(h) < errorAllowed)
|
||||
return;
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user