?? 趨勢面分析f2.frm
字號:
Input #intFileNumber, vntA
Load lblCol(intI)
lblCol(intI).Caption = vntA
Next intI
'形成左邊標簽,但不在窗體上顯示
For intI = 1 To intRowAll
Input #intFileNumber, vntA
Load lblRow(intI)
lblRow(intI).Caption = vntA
Next intI
lblF.Visible = False: lblNum(0).Visible = False
lblN(0).Visible = False: lblC(0).Visible = False
lbltV(0).Visible = False: lbltR(0).Visible = False
Close
End Sub
'計算
Private Sub cmdCalculate_Click()
Dim tt(300) As Single '保存t檢驗值
On Error Resume Next
If txtNN.Text = "" Then
MsgBox "在文本框中需填入趨勢面的次數!"
txtNN.SetFocus
Exit Sub
End If
lblFC.Visible = True: lblCV.Visible = True
lblf005.Visible = True: lbl005F.Visible = True
lblf001.Visible = True: lbl001F.Visible = True
lblFR.Visible = True: lblRR.Visible = True
lblt005.Visible = True: lblt001.Visible = True
lblTT.Visible = True: Line1.Visible = True
N0 = Val(txtNN.Text) 'N0為多項式的次數
NT = 1
For I = 1 To N0
NT = NT + (I + 1) 'NT為多項式的項數
Next
ReDim H(1 To NT), C(1 To NT, 1 To NT)
ReDim b(1 To M, 1 To N) '網格化后的結果
ReDim G(1 To M, 1 To N) '殘差
'計算趨勢面多項式的系數,并求觀測點的趨勢值和殘差值
'X:數組,觀測數據的X坐標
'Y:數組,觀測數據的Y坐標
'Z:數組,觀測數據的Z坐標
'N0:趨勢面的次數
'H:數組,保存趨勢面多項式的系數
'C:保存正規方程系數
'T:數組,保存觀測點的趨勢值
'D:數組,保存觀測點的殘差值
TREND X, Y, Z, N0, H, C, T, D
For I = 1 To intCol
Za = Za + Z(I)
Next I
Za = Za / intCol '因變量的平均值
'Syy是總離差平方和
For K = 1 To intCol
Zyy = Zyy + (Z(K) - Za) ^ 2
Next K
'U是回歸平方和
For I = 1 To intCol 'intCol為觀測點個數
w = 0
XX = X(I): YY = Y(I)
For J = 1 To NT '多項式的項數
Call Power(XX, YY, J, EE, FF)
w = H(J) * EE * FF + w
Next J
U = U + (w - Za) ^ 2
Next I
'Q是殘差平方和
Q = Zyy - U
S2 = Q / (intCol - NT - 2) 'NT為系數的個數,包括常數項
F = (U / (NT - 1)) / S2 'F檢驗值
sngF = F: lblCV.Caption = sngF
UA = NT - 1: Ue = intCol - NT - 2
PF_DIST UA, Ue, 0.05, F005 '計算顯著性為0.05的F臨界值
PF_DIST UA, Ue, 0.01, F001 '計算顯著性為0.01的F臨界值
sngF005 = F005: sngF001 = F001
lbl005F.Caption = Str(sngF005): lbl001F.Caption = Str(sngF001)
If F <= F005 Then lblFR.Caption = "F檢驗結論:" & "不顯著"
If F > F005 And F <= F001 Then lblFR.Caption = "F檢驗結論:" & "顯著"
If F > F001 Then lblFR.Caption = "F檢驗結論:" & "特別顯著"
sngC = U / Zyy * 100 '擬合度
If sngC < 100 Then
lblRR.Caption = "擬合度:" & Str(sngC) & "%"
Else
lblRR.Caption = "擬合度:" & Str(100) & "%"
End If
'求t檢驗值
S2 = Sqr(S2)
Invert C '求正規方程系數矩陣的逆矩陣
For I = 1 To NT - 1
tt(I) = Abs(H(I + 1) / S2 / Sqr(C(I, I)))
Next I
't檢測為雙尾,在求臨界值時,0.05和0.01都需除2
PT_DIST Ue, 0.05 / 2, t005 '計算顯著性為0.05的t臨界值
PT_DIST Ue, 0.01 / 2, t001 '計算顯著性為0.01的t臨界值
sngt005 = t005: sngt001 = t001
lblt005.Caption = sngt005: lblt001.Caption = sngt001
'利用標簽數組顯示趨勢面多項式系數及t檢驗
lblF.Visible = True: lblNum(0).Visible = True
lblN(0).Visible = True: lblC(0).Visible = True
lbltV(0).Visible = True: lbltR(0).Visible = True
sngH = lblN(0).Height '標簽元素的高度
For I = 1 To NT - 1 '置放標簽數組
Load lblN(I): Load lblC(I): Load lbltV(I)
Load lbltR(I): Load lblNum(I)
lblN(I).Move lblN(0).Left, lblN(0).Top + I * sngH
lblC(I).Move lblC(0).Left, lblC(0).Top + I * sngH
lbltV(I).Move lbltV(0).Left, lbltV(0).Top + I * sngH
lbltR(I).Move lbltR(0).Left, lbltR(0).Top + I * sngH
lblNum(I).Move lblNum(0).Left, lblNum(0).Top + I * sngH
lblN(I).Visible = True: lblC(I).Visible = True
lbltV(I).Visible = True: lbltR(I).Visible = True
lblNum(I).Visible = True
Next I
For I = 1 To NT
lblNum(I).Caption = Str(I): lblN(I).Caption = ""
sngC = H(I) 'H()保存趨勢面多項式系數
lblC(I - 1).Caption = Str(sngC) '顯示多項式系數
'求趨勢面各項的形式,以便在標簽中顯示X^2或Y^3等等
'I為項的次數
'intE為X的次數
'intF為Y的次數
Term I, intE, intF
If I > 1 Then
If intE <> 0 Then lblN(I - 1).Caption = "X^" & Str(intE) & " "
If intF <> 0 Then _
lblN(I - 1).Caption = lblN(I - 1).Caption & "Y^" & Str(intF)
End If
sngt = tt(I)
lbltV(I).Caption = Str(sngt) '顯示t檢驗值
'顯示結論
If tt(I) <= t005 Then lbltR(I) = "不顯著"
If tt(I) > t005 And tt(I) <= t001 Then lbltR(I) = "顯著"
If tt(I) > t001 Then lbltR(I) = "特別顯著"
Next I
'網格插值
If Key = 1 Then GRID X, Y, H, b, G
'預測
If Key = 3 Then
lblNotice.Caption = "預測結果"
PreValue X0, Y0, NT, ZZ
sngZ = ZZ: txtNN = Str(sngZ)
End If
'非“預測”情況下,使“保存”命令按鈕可視
If Not Key = 3 Then cmdSaveR.Visible = True
cmdCalculate.Visible = False
End Sub
'垂直滾動條
Private Sub VScroll1_Change()
Dim V As Integer
On Error Resume Next
V = VScroll1.Value
lblNum(0) = "序號": lbltV(0) = "t檢驗值": lbltR(0) = "t檢驗結論"
lbl005F.Caption = Str(sngF005): lbl001F.Caption = Str(sngF001)
For I = 1 To NT
If I + V <= NT Then
lblN(I).Caption = "": lblNum(I).Caption = Str(I + V)
sngC = H(I + V) 'H()保存趨勢面多項式系數
lblC(I - 1).Caption = Str(sngC) '顯示多項式系數
'求趨勢面各項的形式
'I為項的次數
'intE為X的次數
'intF為Y的次數
Term I + V, intE, intF
If I > 1 Then
If intE <> 0 Then lblN(I - 1).Caption = "X^" & Str(intE) & " "
If intF <> 0 Then _
lblN(I - 1).Caption = lblN(I - 1).Caption & "Y^" & Str(intF)
End If
sngt = T(I + V)
lbltV(I).Caption = Str(sngt) '顯示t檢驗值
'顯示結論
If T(I + V) <= t005 Then lbltR(I) = "不顯著"
If T(I + V) > t005 And T(I) <= t001 Then lbltR(I) = "顯著"
If T(I + V) > t001 Then lbltR(I) = "特別顯著"
Else
lblNum(I - 1) = "": lblN(I) = "": lblC(I - 1) = ""
lbltV(I - 1) = "": lbltR(I - 1) = ""
End If
Next I
End Sub
'將計算結果保存為數據文件
Private Sub cmdSaveR_Click()
Dim sngR As Single, intN As Integer
MsgBox "現在存盤,請耐心等待!"
If blnOpt Then
'重新建立網格體系,需要先卸載原有的網格體系
For intI = 1 To intRowAll
For intJ = 1 To intCol
Unload txtData((intI - 1) * intCol + intJ)
Next intJ
Next intI
For intI = 1 To intCol
Unload lblCol(intI)
Next intI
For intI = 1 To intRowAll
Unload lblRow(intI)
Next intI
'保存網格化數據
'網格化時的列數、行數、總行數都有可能改變,需要重新建立網格體系
'重新取得列數、行數、總行數
intRow = M
If blnRowLabel Then
intRowAll = intRowAll - 6 + 2 * M
Else
intRowAll = intRowAll - 3 + M
End If
intCol = N
For intI = 1 To intRowAll
For intJ = 1 To intCol
Load txtData((intI - 1) * intCol + intJ)
Next intJ
Next intI
For intI = 1 To intCol
Load lblCol(intI)
Next intI
For intI = 1 To intRowAll
Load lblRow(intI)
Next intI
lblRow(1).Caption = "列數"
txtData(1).Text = intCol '列數
For intI = 2 To intCol
txtData(intI) = "*******"
Next intI
lblRow(2).Caption = "行數"
txtData(intCol + 1).Text = intRow '行數
For intI = 2 To intCol
txtData(intCol + intI) = "*******"
Next intI
lblRow(3).Caption = "總行數"
txtData(2 * intCol + 1).Text = intRowAll '總行數
For intI = 2 To intCol
txtData(2 * intCol + intI) = "*******"
Next intI
If blnTitle Then '有標題
lblRow(4).Caption = "標題"
txtData(3 * intCol + 1).Text = "網格趨勢"
For intI = 2 To intCol
txtData(3 * intCol + intI) = "*******"
Next intI
intN = 5
End If
If blnRowLabel Then '有行標
For intI = intN To intN + intRow - 1
lblRow(intI).Caption = "行標" & (intI - intN + 1)
txtData((intI - 1) * intCol + 1).Text = " "
For intJ = 2 To intCol
txtData((intI - 1) * intCol + intJ).Text = "*******"
Next intJ
Next intI
intN = intN + intRow
End If
If blnColLabel Then '有列標
lblRow(intN).Caption = "列標"
For intI = 1 To intCol
txtData((intN - 1) * intCol + intI) = " "
Next intI
intN = intN + 1
End If
'數據****************************************************************
For intI = intN To intRowAll
lblRow(intI).Caption = "第" & (intI - intN + 1) & "行"
For intJ = 1 To intCol
sngR = b(intI - intN + 1, intJ)
txtData((intI - 1) * intCol + intJ) = sngR '數據
Next intJ
Next intI
'****************************************************************
For intI = 1 To intCol
lblCol(intI).Caption = "第" & intI & "列"
Next intI
FileSave (strRes_Name)
'保存網格殘差
intN = 4
If blnTitle Then '有標題
txtData(3 * intCol + 1).Text = "網格殘差"
intN = 5
End If
If blnRowLabel Then intN = intN + intRow '有行標
If blnColLabel Then intN = intN + 1 '有列標
'*****************************************************************
For intI = intN To intRowAll
For intJ = 1 To intCol
sngR = G(intI - intN + 1, intJ)
txtData((intI - 1) * intCol + intJ) = sngR '數據
Next intJ
Next intI
'*****************************************************************
FileSave (strErr_Name)
Else
'保存平滑結果和殘差
For intJ = 1 To intCol
sngR = T(intJ)
txtData((intRowAll - 1) * intCol + intJ) = sngR
Next intJ
FileSave (strRes_Name)
For intJ = 1 To intCol
sngR = D(intJ)
txtData((intRowAll - 1) * intCol + intJ) = sngR
Next intJ
FileSave (strErr_Name)
End If
cmdCalculate.Visible = False
cmdSaveR.Visible = False
MsgBox "存盤完成,請退出!"
End Sub
'退出
Private Sub cmdExit_Click()
Unload Me
End
End Sub
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -