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

44
Mullers.m Normal file
View File

@@ -0,0 +1,44 @@
function [xList, functionValueList] = Mullers(f, p0, p1, p2, errorAllowed)
%
%Mullers(f, p0, p1, p2, errorAllowed)
%This function finds the root of a function using Muller's Method
%
pkg load symbolic;
warning('off','OctSymPy:sym:rationalapprox');
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;
while(cnt < maxIt)
b = s2 + h2 * d;
D = (b^2 - (4 * double(subs(f,p2)) * d))^(1/2);
if(abs(b - D) < abs(b + D))
E = b + D;
else
E = b - D;
end
h = (02 * double(subs(f,p2)))/E;
p = p2 + h;
xList(end+1) = p;
functionValueList(end+1) = double(subs(f,p));
if(abs(h) < errorAllowed)
return;
else
p0 = p1;
p1 = p2;
p2 = p;
h1 = p1 - p0;
h2 = p2 - p1;
s1 = (double(subs(f,p1)) - double(subs(f,p0)))/h1;
s2 = (double(subs(f,p2)) - double(subs(f,p1)))/h2;
d = (s2 - s1)/(h2 + h1);
++cnt;
end
end
end