Function nearfast(nx As Single, fastu) As Single
Dim n1 As Single
Dim n2 As Single
Dim n3 As Single
Dim dn As Single
n1 = nx
pp = 0
If n1 > 19 Then pp = -999
If n1 > 19 Then n1 = 1
If n1 < 1 Then pp = -999
If n1 < 1 Then n1 = 1
n2 = Int(n1)
n3 = n2 + 1
dn = (n1 - n2) * (fastu(n3) - fastu(n2))
nearfast = fastu(n2) + dn + pp
End Function
Function fastv(fastu, v) As Single
Dim bs As Single
Dim us As Single
Dim vs As Single
Dim b1 As Single
Dim u1 As Single
Dim v1 As Single
Dim b2 As Single
Dim u2 As Single
Dim v2 As Single
Dim w0 As Single
Dim w1 As Single
Dim w2 As Single
Dim ww As Single
Dim h As Single
Dim vps As Single
bp = 700
h = 3
w0 = Log(0.4) + Log(0.4)
ww = (Log(0.7) + Log(0.7) - w0) / 100
bs = 0
us = nearfast(bs, fastu)
w1 = (us - w0) / ww
vs = nearv(9, w1, -bs, v)
vps = us + vs
t2 = 0
Do Until t2 > 10
t1 = 0
Do Until t1 > 100
b1 = bs + h
u1 = nearfast(b1, fastu)
w1 = (u1 - w0) / ww
v1 = nearv(9, w1, -b1, v)
vp1 = u1 + v1
b2 = bs - h
u2 = nearfast(b2, fastu)
w2 = (u2 - w0) / ww
v2 = nearv(9, w2, -b2, v)
vp2 = u2 + v2
If vp1 > vps Then bs = b1
If vp1 > vps Then vps = vp1
If vp2 > vps Then bs = b2
If vp2 > vps Then vps = vp2
If (bp - bs) ^ 2 < 10 ^ (-5) Then t1 = 1000
bp = bs
t1 = t1 + 1
Debug.Print t1, bs, vps
Loop
h = h / 2
t2 = t2 + 1
Loop
fastv = vps
End Function
Function checku(s As Single, th, bp As Single) As Single
Dim ls As Single
Dim cs As Single
Dim us As Single
Dim ys As Single
Dim ws As Single
Dim l1 As Single
Dim c1 As Single
Dim u1 As Single
Dim l2 As Single
Dim y2 As Single
Dim y1 As Single
Dim c2 As Single
Dim u2 As Single
Dim h As Single
Dim lp As Single
Dim t1 As Single
Dim t2 As Single
Dim e As Single
e = 10 ^ (-5)
h = 0.1
ls = (bp + 0.1) / th(s)
ys = th(s) * ls
cs = ys - bp
us = Log(cs) + Log(1 - ls)
t2 = 0
Do Until t2 > 10
t1 = 0
Do Until t1 > 100
l1 = ls + h
If l1 > 0.99 Then l1 = ls
c1 = th(s) * l1 - bp
y1 = th(s) * l1
u1 = Log(c1) + Log(1 - l1)
l2 = ls - h
If l2 < 0.01 Then l2 = ls
c2 = th(s) * l2 - bp
If c2 < 0.01 Then l2 = ls
c2 = th(10) * l2 - bp
y2 = th(s) * l2
u2 = Log(c2) + Log(1 - l2)
If u1 > us Then ls = l1
If u1 > us Then us = u1
If u2 > us Then ls = l2
If u2 > us Then us = u2
If (lp - ls) ^ 2 < e Then t1 = 1000
lp = ls
t1 = t1 + 1
Loop
h = h / 2
t2 = t2 + 1
Loop
checku = us
End Function
Function seekv(s As Single, mx As Single, nx As Single, u, v) As Single
Dim bs As Single
Dim us As Single
Dim vs As Single
Dim b1 As Single
Dim u1 As Single
Dim v1 As Single
Dim b2 As Single
Dim u2 As Single
Dim v2 As Single
Dim w0 As Single
Dim w1 As Single
Dim w2 As Single
Dim ww As Single
Dim h As Single
Dim vps As Single
bp = 700
h = 3
w0 = Log(0.4) + Log(0.4)
ww = (Log(0.7) + Log(0.7) - w0) / 100
bs = nx
us = nearu(s, mx, bs, u)
w1 = (us - w0) / ww
vs = nearv(s - 1, w1, nx - bs, v)
vps = us + vs
t2 = 0
Do Until t2 > 10
t1 = 0
Do Until t1 > 100
b1 = bs + h
u1 = nearu(s, mx, b1, u)
w1 = (u1 - w0) / ww
v1 = nearv(s - 1, w1, nx - b1, v)
vp1 = u1 + v1
b2 = bs - h
u2 = nearu(s, mx, b2, u)
w2 = (u2 - w0) / ww
v2 = nearv(s - 1, w2, nx - b2, v)
vp2 = u2 + v2
If vp1 > vps Then bs = b1
If vp1 > vps Then vps = vp1
If vp2 > vps Then bs = b2
If vp2 > vps Then vps = vp2
If (bp - bs) ^ 2 < 10 ^ (-5) Then t1 = 1000
bp = bs
t1 = t1 + 1
Loop
h = h / 2
t2 = t2 + 1
Loop
seekv = vps
End Function
Function nearv(s As Single, mx As Single, nx As Single, v) As Single
Dim m1 As Single
Dim m2 As Single
Dim m3 As Single
Dim n1 As Single
Dim n2 As Single
Dim n3 As Single
Dim pp As Single
Dim dm As Single
Dim dn As Single
Dim nv As Single
pp = 0
m1 = mx
n1 = nx
If m1 < 1 Then pp = 1
If m1 < 1 Then m1 = 1
If m1 > 99 Then pp = 1
If m1 > 99 Then m1 = 99
If n1 < -19 Then pp = 1
If n1 < -19 Then n1 = -19
If n1 > 19 Then pp = 1
If n1 > 19 Then n1 = 19
m2 = Int(m1)
m3 = m2 + 1
n2 = Int(n1)
n3 = n2 + 1
dm = (m1 - m2) * (v(s, m3, n2) - v(s, m2, n2))
dn = (n1 - n2) * (v(s, m2, n3) - v(s, m2, n2))
nv = v(s, m2, n2) + dm + dn
If pp = 1 Then nv = -999
nearv = nv
End Function
Function nearu(s As Single, mx As Single, nx As Single, u) As Single
Dim m1 As Single
Dim m2 As Single
Dim m3 As Single
Dim n1 As Single
Dim n2 As Single
Dim n3 As Single
Dim pp As Single
Dim dm As Single
Dim dn As Single
Dim nu As Single
pp = 0
m1 = mx
n1 = nx
If m1 < 1 Then pp = 1
If m1 < 1 Then m1 = 1
If m1 > 99 Then pp = 1
If m1 > 99 Then m1 = 99
If n1 < -19 Then pp = 1
If n1 < -19 Then n1 = -19
If n1 > 19 Then pp = 1
If n1 > 19 Then n1 = 19
m2 = Int(m1)
m3 = m2 + 1
n2 = Int(n1)
n3 = n2 + 1
dm = (m1 - m2) * (u(s, m3, n2) - u(s, m2, n2))
dn = (n1 - n2) * (u(s, m2, n3) - u(s, m2, n2))
nu = u(s, m2, n2) + dm + dn
If pp = 1 Then nu = -999
nearu = nu
End Function
Function seeku(s As Single, th, wp As Single, bp As Single) As Single
Dim ls As Single
Dim cs As Single
Dim us As Single
Dim ys As Single
Dim ws As Single
Dim l1 As Single
Dim c1 As Single
Dim u1 As Single
Dim l2 As Single
Dim y2 As Single
Dim y1 As Single
Dim c2 As Single
Dim u2 As Single
Dim h As Single
Dim lp As Single
Dim t1 As Single
Dim t2 As Single
Dim e As Single
e = 10 ^ (-5)
h = 0.1
ls = (bp + 0.1) / th(s)
ys = th(s) * ls
cs = ys - bp
us = Log(cs) + Log(1 - ls)
ws = Log(cs) + Log(1 - ys / th(s + 1))
If ws > wp Then us = -999
t2 = 0
Do Until t2 > 10
t1 = 0
Do Until t1 > 100
l1 = ls + h
If l1 > 0.99 Then l1 = ls
c1 = th(s) * l1 - bp
y1 = th(s) * l1
u1 = Log(c1) + Log(1 - l1)
w1 = Log(c1) + Log(1 - y1 / th(s + 1))
If w1 > wp Then u1 = -999
l2 = ls - h
If l2 < 0.01 Then l2 = ls
c2 = th(s) * l2 - bp
If c2 < 0.01 Then l2 = ls
c2 = th(s) * l2 - bp
y2 = th(s) * l2
u2 = Log(c2) + Log(1 - l2)
w2 = Log(c2) + Log(1 - y2 / th(s + 1))
If w2 > wp Then u2 = -999
If u1 > us Then ls = l1
If u1 > us Then us = u1
If u2 > us Then ls = l2
If u2 > us Then us = u2
If (lp - ls) ^ 2 < e Then t1 = 1000
lp = ls
t1 = t1 + 1
Loop
h = h / 2
t2 = t2 + 1
Loop
seeku = us
End Function
Private Sub Command1_Click()
Dim u(1 To 9, 1 To 100, -20 To 20) As Single
Dim fastu(-20 To 20) As Single
Dim v(1 To 9, 1 To 100, -20 To 20) As Single
Dim b(-100 To 100) As Single
Dim w(1 To 100) As Single
Dim m As Single
Dim n As Single
Dim w0 As Single
Dim th(1 To 10) As Single
Dim s As Single
For s = 1 To 10
th(s) = 1 + 0.1 * s
Next
For m = -20 To 20
b(m) = 0.01 * m
Next
w1 = Log(0.4) + Log(0.4)
ww = (Log(0.7) + Log(0.7) - w1) / 100
For n = 1 To 100
w(n) = w1 + ww * n
Next
For s = 1 To 9
For m = 1 To 100
For n = -20 To 20
u(s, m, n) = seeku(s, th, w(m), b(n))
Next
Next
Next
For m = 1 To 100
For n = -20 To 20
v(1, m, n) = u(1, m, n)
Next
Next
For s = 2 To 9
For m = 1 To 100
For n = -20 To 20
v(s, m, n) = seekv(s, m, n, u, v)
Next
Next
Next
For n = -20 To 20
fastu(n) = checku(10, th, b(n))
Next
Debug.Print fastv(fastu, v)
End Sub
最終更新:2009年08月07日 13:09