-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMullerMethod.m
76 lines (50 loc) · 1.17 KB
/
MullerMethod.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
% ------------------ OK ---------------
% Muller Method
% MD MAHADI HASAN NAHID
% 30-11-2012, 11:25PM
clear all;
clc;
xr=5;
h=0.5;
x2=xr;
x1=xr+h*xr;
x0=xr-h*xr;
eps=0.001;
maxit=5;
f = [1 0 -13 -12];
fprintf('The True Roots Are:\n');
disp(roots(f));
fprintf('------------------------------------------------\n');
iter = 0;
fprintf('-------------In While Loop--------------\n');
while 1
iter=iter+1;
h0=x1-x0;
h1=x2-x1;
fx1=polyval(f,x1);
fx0=polyval(f,x0);
fx2=polyval(f,x2);
d0=(fx1-fx0)/h0;
d1=(fx2-fx1)/h1;
a=(d1-d0)/(h1+h0);
b=a*h1+d1;
c=fx2;
red=sqrt(b*b-4*a*c);
if abs(b+red) > abs(b-red)
den=b+red;
else
den=b-red;
end
dxr = -(2*c)/den;
xr = x2+dxr;
%[iter xr]
disp(xr);
if abs(dxr) < eps || iter >= maxit
fprintf('-------------The Root--------------\n');
disp(xr);
break;
end
x0=x1;
x1=x2;
x2=xr;
end