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:Na(k)=input('Enter a coefficient ');enda=[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:zdelta0=(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;endif b+sqrt(b^2-4*a*c)<b-sqrt(b^2-4*a*c)d=g2;endx(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?
Best Answer