Function rev(th, p As Single) As Single
Dim s As Single
Dim q1 As Single
Dim cost As Single
cost = 2
r1 = 0
For s = 1 To 100
q1 = d(s, th, p)
r1 = r1 + p * q1 - cost * q1
Next
rev = r1
End Function
Function d(s As Single, th, p As Single) As Single
Dim d1 As Single
d1 = th(s) / p - 1
If d1 < 0 Then d1 = 0
d = d1
End Function
Private Sub Command1_Click()
Dim s As Single
Dim th(1 To 100) As Single
Dim p As Single
Dim n As Single
Dim px(1 To 100) As Single
Dim qx(1 To 100) As Single
Dim r1 As Single
For s = 1 To 100
th(s) = 0.1 * s
Next
maxr = -999
For n = 1 To 200
p = 2 + 0.01 * n
r1 = rev(th, p)
If r1 > maxr Then maxp = p
If r1 > maxr Then maxr = r1
Next
p = maxp
For s = 1 To 100
qx(s) = d(s, th, p)
px(s) = p * qx(s)
Next
Open "c:/lupin.txt" For Output As #1
For s = 1 To 100
Write #1, s, qx(s), px(s)
Next
Close #1
End Sub
最終更新:2009年11月03日 23:49