用vb写牛顿迭代法程序解方程用牛顿迭代法解此方程,请高手帮我写个完整程序,本人菜鸟,写出的表达式老是编译错误.f(x) = (0.366 * q / m / s) * Log(10 * s * sqr(x) / r) - x式中:q,m,s,r都是常量计算
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/26 12:17:32
用vb写牛顿迭代法程序解方程用牛顿迭代法解此方程,请高手帮我写个完整程序,本人菜鸟,写出的表达式老是编译错误.f(x) = (0.366 * q / m / s) * Log(10 * s * sqr(x) / r) - x式中:q,m,s,r都是常量计算
用vb写牛顿迭代法程序解方程
用牛顿迭代法解此方程,请高手帮我写个完整程序,本人菜鸟,写出的表达式老是编译错误.
f(x) = (0.366 * q / m / s) * Log(10 * s * sqr(x) / r) - x
式中:q,m,s,r都是常量
计算精度0.001
hanshu = 0.366 * q / m / s * Log(10 * s * Sqr(x) / r) - x
这一句运行时出现提示:无效的调用或参数
用vb写牛顿迭代法程序解方程用牛顿迭代法解此方程,请高手帮我写个完整程序,本人菜鸟,写出的表达式老是编译错误.f(x) = (0.366 * q / m / s) * Log(10 * s * sqr(x) / r) - x式中:q,m,s,r都是常量计算
Dim q As Single,m As Single,s As Single,r As Single
Private Sub Command1_Click()
Dim x0 As Single
Do
q = Val(InputBox("请输入常数q(≠0) "))
Loop Until q 0
Do
m = Val(InputBox("请输入常数m(≠0) "))
Loop Until m 0
Do
s = Val(InputBox("请输入常数s(≠0) "))
Loop Until s 0
Do
r = Val(InputBox("请输入常数r(≠0) "))
Loop Until r 0
Label1 = Label1 & "q=" & q & " m=" & m & " s=" & s & " r=" & r
Do
x0 = Val(InputBox("请粗略估计解x0(>0) "))
Loop Until x0 > 0
y0 = hanshu(x0)
Do
xielv = daoshu(x0)
deltx = y0 / xielv
x0 = x0 + deltx
y0 = hanshu(x0)
Loop Until Abs(y0) < 0.00005 And Abs(deltx) < 0.00005
Label1 = Label1 & vbCrLf & "x=" & x0 & " y=" & y0 & " Δx=" & deltx
End Sub
Private Sub Command2_Click()
For i = 0 To 255
If i Mod 10 = 0 Then Print
Print Chr$(i); " ";
Next i
Print "ok"
End Sub
Private Sub Form_Load()
Label1 = "(0.366 * q / m / s) * Log(10 * s * sqr(x) / r) - x = 0" & vbCrLf
End Sub
Private Function hanshu(x As Single) As Single
hanshu = 0.366 * q / m / s * Log(10 * s * Sqr(x) / r) - x
End Function
Private Function daoshu(x As Single) As Single
daoshu = 0.366 * q / 2 / x / m / s - 1
End Function
注意参数选择不当,就会出错.