VB编程题,牛顿迭代法。
答案:3 悬赏:20 手机版
解决时间 2021-03-23 23:47
- 提问者网友:情歌越听越心酸
- 2021-03-23 10:54
VB编程题,牛顿迭代法。
最佳答案
- 五星知识达人网友:廢物販賣機
- 2021-03-23 11:25
Private Function NewTon(n As Double, eps As Double) As Double
Dim a(100) As Double
Dim x As Double
Dim y As Double
Dim k As Double
a(0) = 0
For i = 0 To 99
x = a(i)
y = x ^ 3 - 2 * x ^ 2 + 4 * x + 1
k = 3 * x ^ 2 - 4 * x + 4
a(i + 1) = x - y / k
Print a(i + 1)
If Abs(y) < esp Then
NewTon = a(i + 1)
Exit Function
Else
NewTon = 0
End If
Next i
End Function追问大神,我是真正的什么都不懂,我只是把你发的这段原原本本地打进去。运行后什么都没发生。。这是什么原因。。该怎么做。。大神,我是真正的什么都不懂,我只是把你发的这段原原本本地打进去。运行后什么都没发生。。这是什么原因。。该怎么做。。追答我不是大神。我这里只是函数,你要用的时候就填入参数,直接出结果,你自己加一个command按钮,点击后添加print NewTon(0,0.000001),试一试结果。
Dim a(100) As Double
Dim x As Double
Dim y As Double
Dim k As Double
a(0) = 0
For i = 0 To 99
x = a(i)
y = x ^ 3 - 2 * x ^ 2 + 4 * x + 1
k = 3 * x ^ 2 - 4 * x + 4
a(i + 1) = x - y / k
Print a(i + 1)
If Abs(y) < esp Then
NewTon = a(i + 1)
Exit Function
Else
NewTon = 0
End If
Next i
End Function追问大神,我是真正的什么都不懂,我只是把你发的这段原原本本地打进去。运行后什么都没发生。。这是什么原因。。该怎么做。。大神,我是真正的什么都不懂,我只是把你发的这段原原本本地打进去。运行后什么都没发生。。这是什么原因。。该怎么做。。追答我不是大神。我这里只是函数,你要用的时候就填入参数,直接出结果,你自己加一个command按钮,点击后添加print NewTon(0,0.000001),试一试结果。
全部回答
- 1楼网友:行雁书
- 2021-03-23 12:38
引用cslizh的回答:
Private Function NewTon(n As Double, eps As Double) As Double
Dim a(100) As Double
Dim x As Double
Dim y As Double
Dim k As Double
a(0) = 0
For i = 0 To 99
x = a(i)
y = x ^ 3 - 2 * x ^ 2 + 4 * x + 1
k = 3 * x ^ 2 - 4 * x + 4
a(i + 1) = x - y / k
Print a(i + 1)
If Abs(y) < esp Then
NewTon = a(i + 1)
Exit Function
Else
NewTon = 0
End If
Next i
End Functionesp和 eps 笔误喽
Private Function NewTon(n As Double, eps As Double) As Double
Dim a(100) As Double
Dim x As Double
Dim y As Double
Dim k As Double
a(0) = 0
For i = 0 To 99
x = a(i)
y = x ^ 3 - 2 * x ^ 2 + 4 * x + 1
k = 3 * x ^ 2 - 4 * x + 4
a(i + 1) = x - y / k
Print a(i + 1)
If Abs(y) < esp Then
NewTon = a(i + 1)
Exit Function
Else
NewTon = 0
End If
Next i
End Functionesp和 eps 笔误喽
- 2楼网友:底特律间谍
- 2021-03-23 11:48
你会了嘛 怎么做的 我看答案还是看不懂那
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯