アットウィキロゴ

oli

Function seekbud(th, c, y) As Single
Dim m As Single
Dim s As Single
Dim b1 As Single
b1 = 0
For s = 1 To 100
m = prefer(s, th, c, y)
b1 = b1 + y(m) - c(m)
Next
seekbud = b1
End Function




Function wel(tl As Single, tr As Single, th, y) As Single
Dim c(0 To 10) As Single
Dim m As Single
Dim s As Single
Dim b1 As Single
For m = 0 To 10
c(m) = (1 - tl) * y(m) + tr
Next
w1 = 0
For s = 1 To 100
m = prefer(s, th, c, y)
w1 = w1 + Log(c(m)) + Log(1 - y(m) / th(s))
Next
wel = w1
End Function

Function trs(tl As Single, th, y) As Single
Dim tr1 As Single
Dim tr2 As Single
Dim tr3 As Single
Dim b1 As Single
Dim b2 As Single
Dim t As Single
tr1 = 0.01
tr2 = 0.5
b1 = bud(tl, tr1, th, y)
b2 = bud(tl, tr2, th, y)
t = 0
Do Until t > 100
tr3 = (tr1 + tr2) / 2
b3 = bud(tl, tr3, th, y)
If b3 < 0 Then tr2 = tr3
If b3 > 0 Then tr1 = tr3
If b3 ^ 2 < 10 ^ (-3) Then t = 1000
t = t + 1
Loop
trs = tr1
End Function
Function bud(tl As Single, tr As Single, th, y) As Single
Dim c(0 To 10) As Single
Dim m As Single
Dim s As Single
Dim b1 As Single
For m = 0 To 10
c(m) = (1 - tl) * y(m) + tr
Next
b1 = 0
For s = 1 To 100
m = prefer(s, th, c, y)
b1 = b1 + y(m) - c(m)
Next
bud = b1
End Function

Function prefer(s As Single, th, c, y) As Single
Dim m As Single
Dim c1 As Single
Dim l1 As Single
Dim pp As Single
Dim u1 As Single
Dim maxu As Single
Dim maxm As Single
maxu = -999
For m = 0 To 10
c1 = c(m)
l1 = y(m) / th(s)
pp = 0
If l1 > 0.99 Then pp = 1
If pp = 1 Then l1 = 0.5
u1 = Log(c1) + Log(1 - l1)
If pp = 1 Then u1 = -999
If u1 > maxu Then maxm = m
If u1 > maxu Then maxu = u1
Next
prefer = maxm
End Function
Private Sub Command1_Click()
Dim th(1 To 100) As Single
Dim y(0 To 10) As Single
Dim curve(0 To 10) As Single
Dim c(0 To 10) As Single
Dim s As Single
Dim m As Single
Dim n As Single
Dim tl As Single
Dim tr As Single
Dim w1 As Single
Dim cps As Single
Dim cp1 As Single
Dim cp2 As Single
Dim mx As Single
Dim maxw As Single
Dim maxtl As Single
For s = 1 To 100
th(s) = 0.02 * s
Next
For m = 0 To 10
y(m) = 0.15 * m
Next
maxw = -999
For n = 1 To 50
tl = 0.01 * n
tr = trs(tl, th, y)
w1 = wel(tl, tr, th, y)
If w1 > maxw Then maxtl = tl
If w1 > maxw Then maxw = w1
Debug.Print tl, tr, w1
Next
tl = maxtl
tr = trs(tl, th, y)
Debug.Print tl, tr
Debug.Print bud(tl, tr, th, y)
End Sub
最終更新:2009年09月11日 07:57