A complex number in the course of Müller's method
古いコメントを表示
Consider the script below. I am trying to find the roots of
by using Müller's method with initial estimations
N=input('Enter the degree of the main polynomial ');
C=input('Enter the constant ');
for k=1:N
a(k)=input('Enter a coefficient ');
end
a=[C,a];
Pol1=flip(a);
u=input('Enter the first estimate ');
v=input('Enter the second estimate ');
w=input('Enter the third estimate ');
z=input('Enter number of iterations ');
for n=1:z
delta0=(polyval(Pol1, v)-polyval(Pol1, u))/(v-u);
delta1=(polyval(Pol1, w)-polyval(Pol1, v))/(w-v);
h0=v-u;
h1=w-v;
a=(delta1-delta0)/(h1+h0);
b=a*h1+delta1;
c=polyval(Pol1,w);
g1=-2*c/(b+sqrt(b^2-4*a*c));
g2=-2*c/(b-sqrt(b^2-4*a*c));
if b+sqrt(b^2-4*a*c)>b-sqrt(b^2-4*a*c)
d=g1;
end
if b+sqrt(b^2-4*a*c)<b-sqrt(b^2-4*a*c)
d=g2;
end
x(n)=w+d;
u=v;
v=w;
w=x(n);
end
When I run it, MATLAB returns 'Undefined function or variable 'd'. d is calculated to be a complex number. MATLAB returns d when I run
or
separately, but does not do for the code. Why is that so?
or
separately, but does not do for the code. Why is that so?採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Biological and Health Sciences についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!