Skip to content

Commit 96818e4

Browse files
authored
Create False or Falsi Position method.m
1 parent 70ecb7f commit 96818e4

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

False or Falsi Position method.m

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
%{
2+
Input
3+
lower = 0.5
4+
upper = 1.0
5+
Error Accept <= 0.01 %
6+
7+
Output:
8+
0.5000 0.5980 0.5606 6.6615
9+
10+
0.5000 0.5606 0.5573 0.5930
11+
12+
0.5000 0.5573 0.5571 0.0513
13+
14+
0.5000 0.5571 0.5570 0.0044
15+
16+
Call Method: FalsePosition(0.5,1.0,0.01)
17+
%}
18+
19+
function FalsePosition(lw, up, erRate)
20+
21+
xr = callRoot(lw, up);
22+
preXr = xr;
23+
24+
while(true)
25+
temp = callFunction(lw) * callFunction(xr);
26+
if(temp > 0)
27+
lw = xr;
28+
elseif(temp < 0)
29+
up = xr;
30+
else
31+
break;
32+
end
33+
34+
xr = callRoot(lw, up);
35+
36+
perCent = (abs(xr - preXr)/xr) * 100;
37+
output=[lw' up' xr' perCent'];
38+
disp(output);
39+
if(perCent < erRate)
40+
break;
41+
end
42+
preXr = xr;
43+
end
44+
end
45+
46+
function xr = callRoot(lw, up)
47+
xr = up - ((callFunction(up)*(lw - up))/(callFunction(lw) - callFunction(up)));
48+
end
49+
50+
function funVal = callFunction(x)
51+
funVal = power(x, 5) - (8 * power(x, 4)) + (44 * power(x, 3)) - (91 * power(x, 2)) + (85 * x) - 26;
52+
end

0 commit comments

Comments
 (0)