逐次代入法的定义:
Public Class Successive
Dim eps As Double = 0.001
Dim Iteration As Integer = 1000
Public Sub New()
End Sub
Public Sub New(ByVal eps As Double, ByVal iteration As Integer)
Me.eps = eps
Me.Iteration = iteration
End Sub
Public Function Solution(ByVal G As Func(Of Double, Double), ByVal x As Double) As Double
Dim i As Integer = 0
Dim x_new, x_old As Double
x_old = x
Do
i += 1
x_new = G(x_old)
If Math.Abs(x_old - x_new) < eps Then Return x_new
x_old = x_new
Loop While i < Iteration
Throw New Exception()
End Function
End Class
Dim eps As Double = 0.001
Dim Iteration As Integer = 1000
Public Sub New()
End Sub
Public Sub New(ByVal eps As Double, ByVal iteration As Integer)
Me.eps = eps
Me.Iteration = iteration
End Sub
Public Function Solution(ByVal G As Func(Of Double, Double), ByVal x As Double) As Double
Dim i As Integer = 0
Dim x_new, x_old As Double
x_old = x
Do
i += 1
x_new = G(x_old)
If Math.Abs(x_old - x_new) < eps Then Return x_new
x_old = x_new
Loop While i < Iteration
Throw New Exception()
End Function
End Class