-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfixedPoint.m
More file actions
50 lines (48 loc) · 1.1 KB
/
Copy pathfixedPoint.m
File metadata and controls
50 lines (48 loc) · 1.1 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
function [errorFlag,root,eps] = fixedPoint(expression, x0, es, imax)
% root = zeros(imax,1);
% eps = zeros(imax, 1);
root = [0];
eps = [0];
%expression = strcat(expression,'-x');
errorFlag = '';
try
for i = 1 : imax
syms x;
eval('y = [];');
eval('z = 0;');
try
y = subs(expression, x, x0);
z = eval(y);
catch
errorFlag = 'Invalid Func or Div by 0';
return;
end
y = subs(expression,x,z);
eval('fz = 0;');
fz =eval(y);
if(z == Inf)
errorFlag = 'The function diverged';
break;
end
if(z == -Inf)
errorFlag = 'The function diverged';
break;
end
if(fz == z)
root(i) = z;
eps(i) = 0;
break;
end
root(i) = z;
ea = abs(z-x0)/z;
eps(i) = ea;
if(abs(ea) < abs(es))
break;
end
x0 = z;
end
catch
errorFlag = 'Un Identified Error Occurred';
return;
end
end