由于编程需要,在网上搜索一元三次方程的解法,数值解法一般都是用什么迭代法,弦截法搞的.没时间研究.下面是找到的资料
=======================================================
有个公式解法
见数学手册:
x^3 +px + q = 0 的通解是:
x1 = (-q/2+((q/2)^2+ (p/3)^3 )^(1/2) )^(1/3) + ( -q/2 - ( (q/2)^2 + (p/3)^3 )^(1/2) )^(1/3) ;
x2 = m * ( -q/2 + ( (q/2)^2 + (p/3)^3 )^(1/2) )^(1/3) + m^2 * ( -q/2 - ( (q/2)^2 + (p/3)^3 )^(1/2) )^(1/3) ;
x3 = m^2 * ( -q/2 + ( (q/2)^2 + (p/3)^3 )^(1/2) )^(1/3) + m * ( -q/2 - ( (q/2)^2 + (p/3)^3 )^(1/2) )^(1/3) ;
其中:m = ( -1 + i * 3^(1/2) )/2 , m^2 = ( -1 - i * 3^(1/2) )/2
而三次方程的一般形式:
ax^3 + bx^2 + cx + d = 0
两边除以a,后设 x = y - b/3a,就可以化成 y^3 + py + q = 0 的形式:
p = c/a - b^2/(3*a^2), q = (2*b^3)/(27*a^3) - (c*b)/(3*a^2) + d/a ;
然后再用上面的公式就行了。其中x1肯定是实根。
=====================================================
一个解的vb程序,没经过验证,不过应该是可以用的
测试部分:
Private Sub Command1_Click()
Dim x1r As Double, x1i As Double, x2r As Double, x2i As Double, x3r As Double, x3i As Double
Dim ret As String
ret = CubicEquation(5, 4, 3, -12, x1r, x1i, x2r, x2i, x3r, x3i) '5x^3+4x^2+3x-12=0
Debug.Print "~~~~~~~~~~~~~~~~~~~~~~~~" & ret
Debug.Print x1r; " + "; x1i; " i"
Debug.Print x2r; " + "; x2i; " i"
Debug.Print x3r; " + "; x3i; " i"
End Sub
函数:
Private Function CubicEquation _
(ByVal a As Double, ByVal b As Double, ByVal c As Double, ByVal d As Double, _
x1r As Double, x1i As Double, x2r As Double, x2i As Double, x3r As Double, x3i As Double) As String
'Cubic equation(v2.2), coded by www.dayi.net btef (please let this line remain)
Dim e As Double, f As Double, g As Double, h As Double, delta As Double
Dim r As Double, sita As Double, pi As Double, rr As Double, ri As Double
If a = 0 Then
CubicEquation = "Not a cubic equation: a = 0"
Exit Function
End If
'pi = 3.14159265358979
pi = 4 * Atn(1)
b = b / a 'simplify to a=1: x^3+bx^2+cx+d=0
c = c / a
d = d / a
e = -b ^ 2 / 3 + c 'substitute x=y-b/3: y^3+ey+f=0
f = (2 * b ^ 2 - 9 * c) * b / 27 + d
If e = 0 And f = 0 Then
x1r = -b / 3
x2r = x1r
x3r = x1r
CubicEquation = "3 same real roots:"
ElseIf e = 0 Then 'need to deal with e = 0, or it will cause z = 0 later.
r = -f 'y^3+f=0, y^3=-f
r = Cur(r)
x1r = r - b / 3 'a real root
If r > 0 Then 'r never = 0 since g=f/2, f never = 0 there
sita = 2 * pi / 3
x2r = r * Cos(sita) - b / 3
x2i = r * Sin(sita)
Else
sita = pi / 3
x2r = -r * Cos(sita) - b / 3
x2i = -r * Sin(sita)
End If
x3r = x2r
x3i = -x2i
CubicEquation = "1 real root and 2 image roots:"
Else 'substitute y=z-e/3/z: (z^3)^2+fz^3-(e/3)^3=0, z^3=-g+sqr(delta)
g = f / 2 '-q-sqr(delta) is ignored
h = e / 3
delta = g ^ 2 + h ^ 3
If delta < 0 Then
r = Sqr(g ^ 2 - delta)
sita = Argument(-g, Sqr(-delta)) 'z^3=r(con(sita)+isin(sita))
r = Cur(r)
rr = r - h / r
sita = sita / 3 'z1=r(cos(sita)+isin(sita))
x1r = rr * Cos(sita) - b / 3 'y1=(r-h/r)cos(sita)+i(r+h/r)sin(sita), x1=y1-b/3
sita = sita + 2 * pi / 3 'no image part since r+h/r = 0
x2r = rr * Cos(sita) - b / 3
sita = sita + 2 * pi / 3
x3r = rr * Cos(sita) - b / 3
CubicEquation = "3 real roots:"
Else 'delta >= 0
r = -g + Sqr(delta)
r = Cur(r)
rr = r - h / r
ri = r + h / r
If ri = 0 Then
CubicEquation = "3 real roots:"
Else
CubicEquation = "1 real root and 2 image roots:"
End If
x1r = rr - b / 3 'a real root
If r > 0 Then 'r never = 0 since g=f/2, f never = 0 there
sita = 2 * pi / 3
x2r = rr * Cos(sita) - b / 3
x2i = ri * Sin(sita)
Else 'r < 0
sita = pi / 3
x2r = -rr * Cos(sita) - b / 3
x2i = -ri * Sin(sita)
End If
x3r = x2r
x3i = -x2i
End If
End If
End Function
Private Function Cur(v As Double) As Double
If v < 0 Then
Cur = -(-v) ^ (1 / 3)
Else
Cur = v ^ (1 / 3)
End If
End Function
Private Function Argument(a As Double, b As Double) As Double
Dim sita As Double, pi As Double
'pi = 3.14159265358979
pi = 4 * Atn(1)
If a = 0 Then
If b >= 0 Then
Argument = pi / 2
Else
Argument = -pi / 2
End If
Else
sita = Atn(Abs(b / a))
If a > 0 Then
If b >= 0 Then
Argument = sita
Else
Argument = -sita
End If
ElseIf a < 0 Then
If b >= 0 Then
Argument = pi - sita
Else
Argument = pi + sita
End If
End If
End If
End Function
=====================================================
还找到一个叫"盛金公式"的,是个叫范盛金的中国人弄的,个人感觉这个人有点臭屁,不过这个方程好像还是比较有用的
摘录下来
A new means
to solving a problem in mathematics
on the cubic equations in Shengjin’s formulas
三次方程新解法——盛金公式解题法
Shengjin’s Formulas
and Shengjin’s Distinguishing Means
and Shengjin’s Theorems from the Writings
to introduce to you and to solving a problem in mathematics
盛金公式与盛金判别法及盛金定理的运用从这里向您介绍
三次方程应用广泛。用根号解一元三次方程,虽然有著名的卡尔丹公式,并有相应的判别法,但使用卡尔丹公式解题比较复杂,缺乏直观性。范盛金推导出一套直接用a、b、c、d表达的较简明形式的一元三次方程的一般式新求根公式,并建立了新判别法。
盛金公式
Shengjin’s Formulas
一元三次方程aX3+bX2+cX+d=0,(a,b,c,d∈R,且a≠0)。
重根判别式:
A=b2-3ac;
B=bc-9ad;
C=c2-3bd,
总判别式:
Δ=B2-4AC。
当A=B=0时,盛金公式①(WhenA=B=0,Shengjin’s Formula①):
X1=X2=X3=-b/(3a)=-c/b=-3d/c。
当Δ=B2-4AC>0时,盛金公式②(WhenΔ=B2-4AC>0,Shengjin’s Formula②):
X1=(-b-(Y11/3+Y21/3))/(3a);
X2,3=(-2b+Y11/3+Y21/3±31/2 (Y11/3-Y21/3)i)/(6a);
其中Y1,2=Ab+3a (-B±(B2-4AC)1/2)/2,i2=-1。
当Δ=B2-4AC=0时,盛金公式③(WhenΔ=B2-4AC =0,Shengjin’s Formula③):
X1=-b/a+K;X2=X3=-K/2,
其中K=B/A,(A≠0)。
当Δ=B2-4AC<0时,盛金公式④(WhenΔ=B2-4AC<0,Shengjin’s Formula④):
X1= (-b-2A1/2cos(θ/3) )/(3a);
X2,3= (-b+A1/2(cos(θ/3)±31/2sin(θ/3)))/(3a);
其中θ=arccosT,T= (2Ab-3aB)/(2A3/2),(A>0,-1<T<1)。
盛金判别法
Shengjin’s Distinguishing Means
①:当A=B=0时,方程有一个三重实根;
②:当Δ=B2-4AC>0时,方程有一个实根和一对共轭虚根;
③:当Δ=B2-4AC=0时,方程有三个实根,其中有一个两重根;
④:当Δ=B2-4AC<0时,方程有三个不相等的实根。
===================================================
哇靠,这个blog居然有字数限制,而且超出字数,直接删掉,连一点提示都没有,只能郁闷一下了
关于这个定理,参考下面几个连接
http://club.xilu.com/s5518/msgview-49671-2.html
http://club.xilu.com/s5518/msgview-49671-3.html
http://club.xilu.com/s5518/msgview-49671-4.html