-
Notifications
You must be signed in to change notification settings - Fork 0
/
FPI.m
37 lines (30 loc) · 970 Bytes
/
FPI.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
function [root, i, percision] = FPI(f, itrNum, initialGuess, desiredPrecision, maxIterations, mode, table)
%mode 1 for quick, 0 for step
syms g(x)
g(x) = f + x;
disp(g);
xold = initialGuess;
onlyOneIteration = 1;
while (1) && (onlyOneIteration)
if (strcmp(mode, 'Step') ~= 0)
onlyOneIteration = 0;
end
startTime = cputime;
itrNum = itrNum + 1;
xnew = double(subs(g,xold));
error = abs((xnew - xold)/xnew) * 100;
oldData = get(table,'Data');
newData = [oldData; {itrNum, xold, '', xnew, error, cputime - startTime}];
set(table,'Data',newData)
if (error > desiredPrecision) && (itrNum < maxIterations)
xold = xnew;
else
root = xnew;
break;
end
i = itrNum;
root = xnew;
time = 0;
percision = error;
end
end