2018-11-19 回答
用牛顿迭代法求方程'a * x ^ 3 + b * x ^ 2 + c * x + d = 0, 系数a = 1, b = 2, c = 3, d = 4, x在0附近的一个实数根为1.33333333333。算法代码如下:
private sub command1_click() '牛顿迭代法
dim a as double, b as double, c as double, d as double, xx1 as double
dim n as long
a = 1
b = 2
c = 3
d = 4
xx1 = 0 '初始值为0,x在0附近
print nim(a, b, c, d, xx1, n) '方程在xx1附近的根
print n '迭代次数
end sub
'牛顿迭代法newton iteration method
function nim(byval a as double, byval b as double, byval c as double, byval d as double, byval x0 as double, byref n as long) as double
dim x as double, y as double, dy as double, ydy as double, i as long
n = -1 '迭代次数
x = x0
for i = 0 to 1000
y = a * x ^ 3 + b * x ^ 2 + c * x + d