用VB编程解一个一元四次方程 运用牛顿法或二分法

方程如下:AX^4-BX^3-C=0ABC是常数重谢
2024-12-05 04:19:41
推荐回答(1个)
回答1:

'牛顿迭代:
Private Sub Form_Load()
parstr = InputBox("输入A,B,C的值,逗号(英文)隔开")
par = Split(parstr, ",")
If UBound(par) < 2 Then MsgBox "缺少参数": Exit Sub
For i = 0 To 2
If IsNumeric(par(i)) = False Then MsgBox "参数非数字": Exit Sub
Next
Dim x0, y0 As Double: x0 = 2 '迭代初值
Do
y0 = par(0) * x0 ^ 4 - par(1) * x0 ^ 3 - par(2)
yy = (4 * par(0) * x0 ^ 3 - 3 * par(1) * x0 ^ 2)
If yy = 0 Then MsgBox "死循环,将退出。请尝试重新设置迭代初值": Exit Sub
x0 = x0 - (y0 / yy)
Loop Until Abs(y0) < 0.00001
MsgBox "x=" & x0
End Sub