Private Sub Command1_Click()
'PROGRAM D9R4
'Driver for routine SVDFIT
NPT = 100
SPREAD = 0.02
NPOL = 5
Dim X(100), Y(100), SIG(100), A(5), CVM(5, 5)
Dim U(100, 5), V(5, 5), W(5)
'Polynomial fit
IDUM& = -911
MP = NPT
NP = NPOL
For I = 1 To NPT
X(I) = 0.02 * I
Y(I) = 1# + X(I) * (2# + X(I) * (3# + X(I) * (4# + X(I) * 5#)))
Y(I) = Y(I) + SPREAD * GASDEV(IDUM&)
SIG(I) = SPREAD
Next I
Call SVDFIT(X(), Y(), SIG(), NPT, A(), NPOL, U(), V(), W(), MP, NP, CHISQ, "FPOLY")
Call SVDVAR(V(), NPOL, NP, W(), CVM(), NPOL)
Print
Print Tab(5); "Polynomial fit"
Print
For I = 1 To NPOL
Print Tab(5); Format$(A(I), "#.##0000"), " +-",
Print Format$(Sqr(CVM(I, I)), ".#####0")
Next I
Print
Print Tab(5); "Chi-squared "; Format$(CHISQ, "###.####00")
Call SVDFIT(X(), Y(), SIG(), NPT, A(), NPOL, U(), V(), W(), MP, NP, CHISQ, "FLEG")
Call SVDVAR(V(), NPOL, NP, W(), CVM(), NPOL)
Print
Print Tab(5); "Legendre polynomial fit"
For I = 1 To NPOL
Print Tab(5); Format$(A(I), "#.##0000"), " +-",
Print Format$(Sqr(CVM(I, I)), ".#####0")
Next I
Print
Print Tab(5); "Chi-squared "; Format$(CHISQ, "###.####00")
End Sub