3 차 지수 평활 법의 예측

2377 단어 알고리즘
어젯밤 에 학생 들 을 도와 지수 평활 법의 예측 모델 알고리즘 을 세 번 완성 하 는 것 은 매우 간단 하 다.
'==============================================
'  :  .jxzhoumin
'    :2008.6.2
'==============================================
Private Sub CommandButton1_Click()
Call main
End Sub
Sub main()
Dim s1_0, s2_0, s3_0 As Integer
Dim s1, s2, s3 As Integer
Dim n As Integer, x As Integer
Dim at, bt, ct As Integer
Dim a As Double
Dim t As Integer  't
Dim tt As Integer 'T
If Trim(TextBox1.Text) = "" Then
   MsgBox "t     !,     !"
   Exit Sub
End If
If Trim(TextBox2.Text) = "" Then
   MsgBox "T     !,     !"
   Exit Sub
End If
If Trim(TextBox4.Text) = "" Then
   MsgBox "a     !,     !"
   Exit Sub
End If
a = Val(Trim(TextBox4.Text))
n = tj("sheet1") - 1
With Worksheets("sheet1")
s1_0 = (Val(.Cells(2, 2).Value + .Cells(3, 2).Value + .Cells(4, 2).Value)) / 3
s2_0 = s1_0
s3_0 = s2_0
For i = 1 To n
    x = .Cells(i + 1, 2).Value
    If i = 1 Then
        s1 = a * x + (1 - a) * s1_0
        s2 = a * s1 + (1 - a) * s2_0
        s3 = a * s2 + (1 - a) * s3_0
    Else
        s1 = a * x + (1 - a) * .Cells(i, 3).Value
        s2 = a * s1 + (1 - a) * .Cells(i, 4).Value
        s3 = a * s2 + (1 - a) * .Cells(i, 5).Value
    End If
    .Cells(i + 1, 3).Value = Int(s1 + 0.5)
    .Cells(i + 1, 4).Value = Int(s2 + 0.5)
    .Cells(i + 1, 5).Value = Int(s3 + 0.5)
Next i
t = Val(Trim(TextBox1.Text))
tt = Val(Trim(TextBox2.Text))
i = 0
Do
    i = i + 1
    If t = .Cells(i + 1, 1) Then
        s1 = .Cells(i + 1, 3).Value
        s2 = .Cells(i + 1, 4).Value
        s3 = .Cells(i + 1, 5).Value
        x = .Cells(i + 1, 2).Value
        Exit Do
    End If
Loop Until i > n
at = 3 * s1 - 3 * s2 + s3
bt = (a / (2 * ((1 - a) ^ 2))) * ((6 - 5 * a) * s1 - 2 * (5 - 4 * a) * s2 + (4 - 3 * a) * s3)
ct = (a ^ 2 / (2 * ((1 - a) ^ 2))) * (s1 - 2 * s2 + s3)
TextBox3.Text = Int(at + bt * tt + ct * (tt ^ 2) + 0.5)
TextBox5.Text = Int(at + 0.5)
TextBox6.Text = Int(bt + 0.5)
TextBox7.Text = Int(ct + 0.5)
End With
End Sub
Function tj(lb) As Integer
     Dim k As Integer
     k = 2
     Do
         Set myR = Sheets(lb).Cells(k, 1)
         If Trim(myR.Value) = "" Then     '     
            Exit Do
         End If
         k = k + 1
     Loop Until False
     tj = k - 1
End Function

좋은 웹페이지 즐겨찾기