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:
31
FalsePosition.m
Normal file
31
FalsePosition.m
Normal file
@@ -0,0 +1,31 @@
|
||||
function [xList, errorList] = FalsePosition(f, p0, p1, errorAllowed)
|
||||
%
|
||||
%FalsePosition(f, p0, p1, errorAllowed)
|
||||
%This function finds the root of a function using the method of False Position
|
||||
%
|
||||
|
||||
pkg load symbolic;
|
||||
warning('off','OctSymPy:sym:rationalapprox');
|
||||
maxIt = 50;
|
||||
cnt = 2;
|
||||
q0 = double(subs(f,p0));
|
||||
q1 = double(subs(f,p1));
|
||||
p = 0;
|
||||
q = 0;
|
||||
currentError = errorAllowed + 1;
|
||||
while((cnt <= maxIt) && (currentError >= errorAllowed))
|
||||
p = p1 - (q1 * (p1 - p0))/(q1 - q0);
|
||||
currentError = abs(p - p1);
|
||||
%Add Values to lists
|
||||
xList(end+1) = p;
|
||||
errorList(end+1) = currentError;
|
||||
++cnt;
|
||||
q = double(subs(f,p));
|
||||
if((q * q1) < 0)
|
||||
p0 = p1;
|
||||
q0 = q1;
|
||||
end
|
||||
p1 = p;
|
||||
q1 = q;
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user