アットウィキロゴ

yanagi

Function com(w1 As Single, w2 As Single, tr As Single) As Single
Dim l1 As Single
l1 = mlab(w1, w2, tr)
l2 = flab(w1, w2, tr)
com = w1 * l1 + w2 * l2 + tr
End Function

Function mlab(w1 As Single, w2 As Single, tr As Single) As Single
Dim l1 As Single
Dim l2 As Single
l1 = (2 * w1 - w2 - tr) / (3 * w1)
l2 = (2 * w2 - w1 - tr) / (3 * w2)
If l2 < 0 Then l1 = (w1 - tr) / (2 * w1)
If l1 < 0 Then l1 = 0
mlab = l1
End Function
Function flab(w1 As Single, w2 As Single, tr As Single) As Single
Dim l1 As Single
Dim l2 As Single
l1 = (2 * w1 - w2 - tr) / (3 * w1)
l2 = (2 * w2 - w1 - tr) / (3 * w2)
If l1 < 0 Then l2 = (w2 - tr) / (2 * w2)
If l2 < 0 Then l2 = 0
flab = l2
End Function
Function u(s As Single, th1, th2, c1 As Single, y1 As Single, y2 As Single) As Single
Dim lx As Single
Dim cx As Single
Dim px As Single
l1 = y1 / th1(s)
l2 = y2 / th2(s)
cx = c1
px = 0
If cx < 0.01 Then px = 1
If l1 > 0.99 Then px = 1
If l2 > 0.99 Then px = 1
If l1 < 0 Then px = 1
If l2 < 0 Then px = 1
If px = 1 Then cx = 0.5
If px = 1 Then l1 = 0.5
If px = 1 Then l2 = 0.5
ux = Log(cx) + Log(1 - l1) + Log(1 - l2)
If px = 1 Then ux = -999
u = ux
End Function
Function tls(th1, th2) As Single
Dim n As Single
Dim m As Single
Dim tl As Single
Dim tk As Single
Dim tr As Single
Dim maxw As Single
Dim maxtl As Single
Dim w1 As Single
maxw = -999
For m = 0 To 50
For n = 1 To 50
tl = 0.01 * m
tk = 0.01 * n
tr = trs(tl, tk, th1, th2)
w1 = wel(tl, tk, tr, th1, th2)
If w1 > maxw Then maxtl = tl
If w1 > maxw Then maxw = w1
Next
Next
tls = maxtl
End Function
Function tks(th1, th2) As Single
Dim n As Single
Dim m As Single
Dim tl As Single
Dim tk As Single
Dim tr As Single
Dim maxw As Single
Dim maxtl As Single
Dim w1 As Single
maxw = -999
For m = 0 To 50
For n = 1 To 50
tl = 0.01 * m
tk = 0.01 * n
tr = trs(tl, tk, th1, th2)
w1 = wel(tl, tk, tr, th1, th2)
If w1 > maxw Then maxtk = tk
If w1 > maxw Then maxw = w1
Next
Next
tks = maxtk
End Function

Function trs(tl As Single, tk As Single, th1, th2) As Single
Dim m As Single
Dim tr1 As Single
Dim tr2 As Single
Dim tr3 As Single
Dim b1 As Single
Dim b2 As Single
Dim b3 As Single
Dim t As Single
tr1 = 0.01
b1 = bud(tl, tk, tr1, th1, th2)
tr2 = 0.5
b2 = bud(tl, tk, tr2, th1, th2)
t = 0
Do Until t > 100
tr3 = (tr1 + tr2) / 2
b3 = bud(tl, tk, tr3, th1, th2)
If b3 > 0 Then b1 = b3
If b3 > 0 Then tr1 = tr3
If b3 < 0 Then b2 = b3
If b3 < 0 Then tr2 = tr3
If b3 ^ 2 < 10 ^ (-5) Then t = 1000
t = t + 1
Loop
trs = tr1
End Function
Function bud(tl As Single, tk As Single, tr As Single, th1, th2) As Single
Dim b1 As Single
Dim c1 As Single
Dim s As Single
Dim m As Single
Dim w1 As Single
Dim w2 As Single
b1 = 0
For s = 1 To 100
w1 = (1 - tl) * th1(s)
w2 = (1 - tk) * th2(s)
y1 = th1(s) * mlab(w1, w2, tr)
y2 = th2(s) * flab(w1, w2, tr)
c1 = com(w1, w2, tr)
b1 = b1 + y1 + y2 - c1
Next
bud = b1
End Function
Function wel(tl As Single, tk As Single, tr As Single, th1, th2) As Single
Dim ws As Single
Dim s As Single
Dim m As Single
Dim c1 As Single
Dim y1 As Single
Dim y2 As Single
Dim w1 As Single
Dim w2 As Single
ws = 0
For s = 1 To 100
w1 = (1 - tl) * th1(s)
w2 = (1 - tk) * th2(s)
y1 = th1(s) * mlab(w1, w2, tr)
y2 = th2(s) * flab(w1, w2, tr)
c1 = com(w1, w2, tr)
ws = ws + u(s, th1, th2, c1, y1, y2)
Next
wel = ws
End Function
Private Sub Command1_Click()
Dim s As Single
Dim m As Single
Dim th1(1 To 100) As Single
Dim th2(1 To 100) As Single
Dim y1(0 To 100) As Single
Dim y2(0 To 100) As Single
Dim c(0 To 100) As Single
Dim tl As Single
Dim tk As Single
Dim tr As Single
Dim s1 As Single
Dim c1 As Single
Dim w1 As Single
Dim w2 As Single
s1 = 1
s2 = 1
For s = 1 To 100
th1(s) = 0.2 * s1
th2(s) = 0.1 * s2
s1 = s1 + 1
If s1 = 11 Then s2 = s2 + 1
If s1 = 11 Then s1 = 1
Next
tl = tls(th1, th2)
tk = tks(th1, th2)
tr = trs(tl, tk, th1, th2)
Debug.Print tl, tk, tr
For s = 1 To 100
w1 = (1 - tl) * th1(s)
w2 = (1 - tk) * th2(s)
y1(s) = th1(s) * mlab(w1, w2, tr)
y2(s) = th2(s) * flab(w1, w2, tr)
c(s) = com(w1, w2, tr)
Next

Open "c:/f1.txt" For Output As #1
For s = 1 To 100
Write #1, s, c(s), y1(s), y2(s)
Next
Close #1
End Sub
最終更新:2009年10月17日 03:54