主题:[讨论]新手求教!急!!!
helenly
[专家分:0] 发布于 2009-04-14 19:55:00
我是初学VB急着毕业。现在的问题是我遇到一个5元一次的含有ln的非线性方程组。请问高手怎么求解,用什么算法,越详细越好。小妹急着毕业!多谢了!!!
回复列表 (共1个回复)
沙发
糊涂大虫 [专家分:580] 发布于 2009-04-16 17:23:00
下面是下降法求非线性方程组的解,是三元的。五元要改一下,方程也要改的。
Private X(20) As Single
Private DFDX(20) As Single
Private N As Integer
Rem ******** This is code:
Private Sub Form_Load()
Form1.Show
Print "This is Ok"
N = 3
I = 1
Do While I <= 3
X(I) = 0.5
I = I + 1
Loop
Print X(1) & X(2) & X(3)
Call NLS
Print X(1) & X(2) & X(3)
End Sub
'*****在下面改变函数表达式:
Private Function F(X)
Dim Y1 As Single
Dim Y2 As Single
Dim Y3 As Single
Y1 = X(1) ^ 2 + X(2) ^ 2 + X(3) ^ 2 - 1
Y2 = 2 * X(1) ^ 2 + X(2) ^ 2 - 4 * X(3)
Y3 = 3 * X(1) ^ 2 - 4 * X(2) + X(3) ^ 2
F = Y1 * Y1 + Y2 * Y2 + Y3 * Y3
End Function
'**X=0.785170,0.496578,0.369894.********
'***************************************
Private Sub NLS()
Dim EPS As Single, R As Single
Dim SUM As Single, W As Single
Dim DXI As Single, RLD As Single
Dim N1 As Integer
EPS = 0.00000001
N1 = 0
R = F(X)
10 SUM = 0
N1 = N1 + 1
Rem *************
For I = 1 To N
W = X(I)
If W = 0 Then
DXI = 0.000001
Else
DXI = W * 0.000001
End If
X(I) = W + DXI
DFDX(I) = (F(X) - R) / DXI
SUM = DFDX(I) ^ 2 + SUM
X(I) = W
Next I
Rem ***************
RLD = R / SUM
I = 1
Do While I <= N
X(I) = X(I) - RLD * DFDX(I)
I = I + 1
Loop
R = F(X)
' Print X(1) & X(2) & X(3)
' If R > EPS Then
If N1 <= 30 Then
GoTo 10
End If
End Sub
我来回复