Laguerre获得多根的方法

时间:2017-12-04 11:48:15

标签: matlab

我必须使用Laguerre的方法编写一段代码来查找poly的真实和复杂根: f(x)= a4x4 + a3x3 + a2x2 + a1x + a0,[a4 a3 a2 a1 a0] = [ - 2 5 5 2 1] 我得到了一些东西:

function y = laguerre (x,coef)
tol = 10^(-10);
%polynomial order
n = length(coef);
i = 0;
while (abs(polyval(coef,x)) > tol)
i = i + 1
x
polyval(coef,x)
%second derivative
a=polyval(polyder(polyder(coef)), x);
%first derivative
b=polyval(polyder(coef), x);
%polynomial value
c=polyval(coef, x);
%square root
r = sqrt((n-1)*[(n-1)*b^2-n*a*c]);
d1 = b + r;
d2 = b - r;
%highest abs value denominator chosen
if (abs(d1) > abs(d2))
    d = d1;
else
    d = d2;
end
%next iteration value obtained
z = n*c/d;
x = x - z;
end
i = i + 1
x
polyval(coef,x)
y = x;
return
end

我想绘制和/或获得我的根源:

coef = [-2 5 5 2 1];
fh = @poly;
%diary on
%plot of the function
figure(1);
fplot(fh, [-500 500]);
hold on;
figure(2);
fplot(fh, [-1.5 3]);
hold on;
%roots obtained using MM2
%z1(1) = MM2(-500,coef);
%z1(2) = MM2(500,coef);
%z1(3) = MM2(1 + i, coef);
%z1(4) = MM2(0 - 2i, coef);
%roots obtained using Laguerre's 
%z2(1) = laguerre(-500,coef);
z2(2) = laguerre(500,coef);
%z2(3) = laguerre(1 + i, coef);
%z2(4) = laguerre(0 - 2i, coef);
%additional points on plot
p = [z1(1) z2(2)];
plot(p,[0 0],'r*');
legend('function','zeros');
hold off;
figure(1);
plot(p,[0 0],'r*');
plot([-500 500],[0 0], 'b*');
legend('function','zeros','START points');
diary off;
hold off;

如您所见,代码的某些部分已被评论,因为我真的不知道如何继续前进。我收到很多警告。我在代码的第一部分有一个错误。我正在寻找一些提示或指导该做什么。

1 个答案:

答案 0 :(得分:1)

你的代码运作得很好,你应该得到根源

x=-500     =>  x=-0.6694729, p(x)=-8.882D-16 in 9 steps 
x= 500     =>  x=3.3489712, p(x)=1.621D-14 in 8 steps  
x=1 + i    =>  x=-0.0897491+i*0.4636332, p(x)=i*8.327D-17 in 4 steps  
x=0 - 2i   =>  x=-0.0897491-i*0.4636332, p(x)=i*5.551D-17 in 4 steps 

为了说明更大的图片,使用[-4,4]+[-4,4]*i中的初始值的Laguerre方法的迭代图看起来像

Laguerre fractal

每个色调代表一步。在这个多项式中没有任何恶意阻止该方法的收敛。

要与之比较,Halley迭代图是

Halley fractal

和牛顿分形

Newton fractal