-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFalse or Falsi Position method.m
More file actions
52 lines (40 loc) · 1.12 KB
/
Copy pathFalse or Falsi Position method.m
File metadata and controls
52 lines (40 loc) · 1.12 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
51
52
%{
Input
lower = 0.5
upper = 1.0
Error Accept <= 0.01 %
Output:
0.5000 0.5980 0.5606 6.6615
0.5000 0.5606 0.5573 0.5930
0.5000 0.5573 0.5571 0.0513
0.5000 0.5571 0.5570 0.0044
Call Method: FalsePosition(0.5,1.0,0.01)
%}
function FalsePosition(lw, up, erRate)
xr = callRoot(lw, up);
preXr = xr;
while(true)
temp = callFunction(lw) * callFunction(xr);
if(temp > 0)
lw = xr;
elseif(temp < 0)
up = xr;
else
break;
end
xr = callRoot(lw, up);
perCent = (abs(xr - preXr)/xr) * 100;
output=[lw' up' xr' perCent'];
disp(output);
if(perCent < erRate)
break;
end
preXr = xr;
end
end
function xr = callRoot(lw, up)
xr = up - ((callFunction(up)*(lw - up))/(callFunction(lw) - callFunction(up)));
end
function funVal = callFunction(x)
funVal = power(x, 5) - (8 * power(x, 4)) + (44 * power(x, 3)) - (91 * power(x, 2)) + (85 * x) - 26;
end