VB 通过迭代法求x的立方根,帮我看怎么改错
Dimx1&,x0&,a&,t!PrivateSubButton1_Click(ByValsenderAsSystem.Object,ByValeAsSystem.Eve...
Dim x1&, x0&, a&, t!
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox1.Text = a
x0 = a
Do
x1 = (2 / 3) * x0 + (a / (3 * x0 * x0))
t = x0
x0 = x1
Loop Until Math.Abs(x0 - t) < 10 ^ (-5)
Label1.Text = x1
End Sub
运行的时候显示 x1 = (2 / 3) * x0 + (a / (3 * x0 * x0))算术运算导致溢出 展开
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox1.Text = a
x0 = a
Do
x1 = (2 / 3) * x0 + (a / (3 * x0 * x0))
t = x0
x0 = x1
Loop Until Math.Abs(x0 - t) < 10 ^ (-5)
Label1.Text = x1
End Sub
运行的时候显示 x1 = (2 / 3) * x0 + (a / (3 * x0 * x0))算术运算导致溢出 展开
2个回答
展开全部
你的 T 有意义吗?我的求解过程:
Dim 实数 As Integer = 3
Dim X0 As Double = 实数
Do
Dim X1 As Double = (2 / 3) * X0 + (实数 / (3 * X0 ^ 2))
X0 = X1
If Math.Abs(X0 ^ 3 - 实数) <= 10 ^ -5 Then
MsgBox("立方根:" & X0)
Exit Do
End If
Loop
你试试哈,只要得出结果的立方与实数的立方差距小于 10^-5 即可。你用你的方式得到“实数”就行了
Dim 实数 As Integer = 3
Dim X0 As Double = 实数
Do
Dim X1 As Double = (2 / 3) * X0 + (实数 / (3 * X0 ^ 2))
X0 = X1
If Math.Abs(X0 ^ 3 - 实数) <= 10 ^ -5 Then
MsgBox("立方根:" & X0)
Exit Do
End If
Loop
你试试哈,只要得出结果的立方与实数的立方差距小于 10^-5 即可。你用你的方式得到“实数”就行了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询