请大家帮忙看看我编的龙格库塔法为什么不对,结果老不正确
Public Class Form1Public K1 As Double, K2 As Double, K3 As Double, K4 As Double
Public h As Double, n As Integer, a As Double, b As Double
Public xk(1000) As Double, yk(1000) As Double, x0 As Double, y0 As Double
Public result As Double
Public Function f(ByVal x As Double, ByVal y As Double) As Double
Dim res As Double
res = y - 2.0 * x / y
Return res
End Function
Public Function COMpute() As Double
Dim i As Integer
xk(0) = x0 : yk(0) = y0
For i = 0 To n
xk(i + 1) = xk(i) + h
K1 = h * f(xk(i), yk(i))
K2 = h * f(xk(i) + 0.5 * h, yk(i) + 0.5 * K1)
K3 = h * f(xk(i) + 0.5 * h, yk(i) + 0.5 * K2)
K4 = h * f(xk(i) + h, yk(i) + K3)
yk(i + 1) = yk(i) + (K1 + 2 * K2 + 2 * K3 + K4) / 6
Next
Return yk(i)
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCompute.Click
a = Val(txta.Text) : b = Val(txtb.Text) : h = Val(txth.Text)
n = (b - a) / h
x0 = Val(txtx0.Text) : y0 = Val(txty0.Text)
result = COMpute()
txtResult.Text = result
End Sub
End Class
这个是代码,图形界面是看附件,版主,帮帮忙啊,您最厉害了