MATLAB实现一元三次方程求解/盛金公式

MATLAB实现一元三次方程求解/盛金公式

一元三次方程求解中,1945年卡尔丹诺把冯塔纳的三次方程求根公式发表出来,但该公式形式比较复杂,直观性也较差。1989年范盛金对一元三次方程求解进行了深入的研究和探索,提出了更加简洁实用的求解公式-盛金公式。这里对盛金公式进行简要的介绍,并给出MATLAB实现的具体代码和部分算例。参考资料:百度百科-卡尔丹公式;百度百科-盛金公式

一元三次方程求解–盛金公式

一元三次方程 a x 3 + b x 2 + c x + d = 0 ax^3 +bx^2+cx+d=0 ax3+bx2+cx+d=0 重根判别式 A = b 2 − 3 a c A=b^2-3ac A=b23ac B = b c − 9 a d B=bc-9ad B=bc9ad C = c 2 − 3 b d C=c^2-3bd C=c23bd总判别式 Δ = B 2 − 4 A C \Delta=B^2-4AC Δ=B24AC

下面给出盛金判别法的结论

条件1 A = B = 0 A=B=0 A=B=0时: x 1 = x 2 = x 3 = − b 3 a = − c b = − 3 d c x1=x2=x3= \frac{-b}{3a}= \frac{-c}{b}= \frac{-3d}{c} x1=x2=x3=3ab=bc=c3d
条件2 Δ = B 2 − 4 A C > 0 \Delta=B^2-4AC>0 Δ=B24AC>0时: x 1 = − b − ( Y 1 3 + Y 2 3 ) 3 a x1= \frac{-b-(\sqrt[3]{Y1}+\sqrt[3]{Y2})}{3a} x1=3ab(3Y1 +3Y2 ) x 2 = − b + 0.5 ( Y 1 3 + Y 2 3 ) + 0.5 3 ( Y 1 3 − Y 2 3 ) i 3 a x2=\frac{-b+0.5(\sqrt[3]{Y1}+\sqrt[3]{Y2})+ 0.5{\sqrt{3}} (\sqrt[3]{Y1}-\sqrt[3]{Y2})i}{3a} x2=3ab+0.5(3Y1 +3Y2 )+0.53 (3Y1 3Y2 )i x 3 = − b + 0.5 ( Y 1 3 + Y 2 3 ) − 0.5 3 ( Y 1 3 − Y 2 3 ) i 3 a x3=\frac{-b+0.5(\sqrt[3]{Y1}+\sqrt[3]{Y2})- 0.5{\sqrt{3}} (\sqrt[3]{Y1}-\sqrt[3]{Y2})i}{3a} x3=3ab+0.5(3Y1 +3Y2 )0.53 (3Y1 3Y2 )i其中, Y 1 = A b + 1.5 a ( − B + B 2 − 4 A C ) Y1=Ab+1.5a({-B+\sqrt{B^2-4AC}}) Y1=Ab+1.5a(B+B24AC ) Y 2 = A b + 1.5 a ( − B − B 2 − 4 A C ) Y2=Ab+1.5a({-B-\sqrt{B^2-4AC}}) Y2=Ab+1.5a(BB24AC )
条件3 Δ = B 2 − 4 A C = 0 \Delta=B^2-4AC=0 Δ=B24AC=0时: x 1 = B A − b a x1= \frac{B}{A}- \frac{b}{a} x1=ABab x 2 = x 3 = − B 2 A x2= x3= -\frac{B}{2A} x2=x3=2AB
条件4 Δ = B 2 − 4 A C < 0 \Delta=B^2-4AC<0 Δ=B24AC<0时: x 1 = − b − 2 A c o s θ 3 3 a x1= \frac{-b-2\sqrt{A}cos{\frac{\theta}{3}}}{3a} x1=3ab2A cos3θ x 2 = − b + A ( c o s θ 3 + 3 s i n θ 3 ) 3 a x2= \frac{-b+\sqrt{A}(cos{\frac{\theta}{3}}+\sqrt{3}sin{\frac{\theta}{3}}) }{3a} x2=3ab+A (cos3θ+3 sin3θ) x 3 = − b + A ( c o s θ 3 − 3 s i n θ 3 ) 3 a x3= \frac{-b+\sqrt{A}(cos{\frac{\theta}{3}}-\sqrt{3}sin{\frac{\theta}{3}}) }{3a} x3=3ab+A (cos3θ3 sin3θ) 其中, θ = arccos ⁡ T \theta=\arccos{T} θ=arccosT T = 2 A b − 3 a B 2 A A T=\frac{2Ab-3aB}{2A\sqrt{A}} T=2AA 2Ab3aB
此外,推导得到的盛金定理表明任意实系数的一元三次方程都可以运用盛金公式解算
通过上述4个条件即可求得一元三次方程的所有根(实根和虚根)。

MATLAB代码-盛金公式

function x = Solve3Polynomial(a, b, c, d)
% 范盛金. 一元三次方程的新求根公式与新判别法[J]. 海南师范学院学报,1989,2(2):91-98.
A = b*b - 3*a*c;   if abs(A) < 1e-14;    A = 0;  end
B = b*c - 9*a*d;   if abs(B) < 1e-14;    B = 0;  end
C = c*c - 3*b*d;   if abs(C) < 1e-14;    C = 0;  end  
DET = B*B - 4*A*C; if abs(DET) < 1e-14;  DET = 0;  end  
if (A == 0) && (B == 0)
    x1 = -c/b;      x2 = x1 ;    x3 = x1;
end
if DET > 0
    Y1 = A*b + 1.5*a*(-B + sqrt(DET));
    Y2 = A*b + 1.5*a*(-B - sqrt(DET));
    y1 = nthroot(Y1,3);  y2 = nthroot(Y2,3);
    x1 = (-b-y1-y2)/(3*a);
    vec1 = (-b + 0.5*(y1 + y2))/(3*a);  
    vec2 = 0.5*sqrt(3)*(y1 - y2)/(3*a);
    x2 = complex(vec1, vec2);
    x3 = complex(vec1, -vec2);
    clear Y1 Y2 y1 y2 vec1 vec2;
end
if DET == 0 && (A ~= 0) && (B ~= 0)
    K = (b*c-9*a*d)/(b*b - 3*a*c); K = round(K,14);
    x1 = -b/a + K;   x2 = -0.5*K;   x3 = x2;
end
if DET < 0
    sqA = sqrt(A);
    T = (A*b - 1.5*a*B)/(A*sqA);
    theta = acos(T);
    csth  = cos(theta/3);
    sn3th = sqrt(3)*sin(theta/3);
    x1 = (-b - 2*sqA*csth)/(3*a);
    x2 = (-b + sqA*(csth + sn3th))/(3*a);
    x3 = (-b + sqA*(csth - sn3th))/(3*a);
    clear sqA T theta csth sn3th;
end
x = [x1;  x2;  x3];
end

值得说明的是:当得到的3个解中至少存在一个复数根时,matlab会将实数结果显示为 a + 0.0000000 i a+0.0000000i a+0.0000000i的形式。

算例验证

算例1: x 3 + 5.4 x 2 + 9.72 x + 5.832 = 0 x^3+5.4x^2+9.72x+5.832=0 x3+5.4x2+9.72x+5.832=0

参考值: x 1 = x 2 = x 3 = 1.8 x1=x2=x3=1.8 x1=x2=x3=1.8
MATLAB实现一元三次方程求解/盛金公式_第1张图片

算例2: 2 x 3 + 11 x 2 + 182 x + 255 = 0 2x^3+11x^2+182x+255=0 2x3+11x2+182x+255=0

参考值: x 1 = − 1.5 ; x 2 = − 2 + 9 i ; x 3 = − 2 − 9 i x1=-1.5; x2=-2+9i;x3=-2-9i x1=1.5x2=2+9ix3=29i
MATLAB实现一元三次方程求解/盛金公式_第2张图片

算例3: x 3 + 5.5 x 2 + 9.92 x + 5.888 = 0 x^3+5.5x^2+9.92x+5.888=0 x3+5.5x2+9.92x+5.888=0

参考值: x 1 = − 2.3 ; x 2 = x 3 = − 1.6 x1=-2.3; x2=x3=-1.6 x1=2.3x2=x3=1.6
MATLAB实现一元三次方程求解/盛金公式_第3张图片

算例4: 100 x 3 − 420 x 2 + 467 x − 105 = 0 100x^3-420x^2+467x-105=0 100x3420x2+467x105=0

参考值: x 1 = 0.3 ; x 2 = 2.5 ; x 3 = 1.4 x1=0.3; x2=2.5; x3=1.4 x1=0.3x2=2.5x3=1.4
MATLAB实现一元三次方程求解/盛金公式_第4张图片

上述4个算例可以看出,MATLAB实现过程中基本无误。

你可能感兴趣的:(MATLAB实现一元三次方程求解/盛金公式)