RosettaCodeData/Task/Multiple-regression/M2000-Interpreter/multiple-regression.m2000

68 lines
1.4 KiB
Plaintext

Module Task_Multiple_regression{
Function Multiple_regression(X(), Y()){
Form 14*5, 32
Print $(0, 14)
integer M=2, Q=3, n=len(x())-1
Dim s(0 to 2*M), t(0 to 2*M)
For k = 0 To 2*M
S(k) = 0 : T(k) = 0
For i = 0 To N
S(k) += X(i) ^ k
If k <= M Then T(k) += Y(i) * X(i) ^ k
Next i
Next k
dim a(0 to M, 0 to Q)
For r = 0 To M
For c = 0 To M
A(r, c) = S(r+c)
Next c
A(r, c) = T(r)
Next r
Print "Linear system coefficents:"
Print $("0.0")
For i = 0 To M
For j = 0 To M+1
Print A(i,j),
Next j
Print
Next i
Print $(0)
For j = 0 To M
For i = j To M
If A(i,j) <> 0 Then Exit For
Next i
If i = M+1 Then
Print "SINGULAR MATRIX"
break
End If
For k = 0 To M+1
Swap A(j,k), A(i,k)
Next k
z = 1 / A(j,j)
For k = 0 To M+1
A(j,k) = z * A(j,k)
Next k
For i = 0 To M
If i <> j Then
z = -A(i,j)
For k = 0 To M+1
A(i,k) += z * A(j,k)
Next k
End If
Next i
Next j
Flush
For i = 0 To M
data A(i,M+1)
Next i
=array([])
}
Dim Solution()
DataX=(1.47,1.50,1.52,1.55,1.57, 1.60,1.63,1.65,1.68, 1.70,1.73,1.75,1.78,1.80,1.83)
DataY=(52.21,53.12,54.48,55.84,57.20,58.57,59.93,61.29,63.11,64.47, 66.28,68.10,69.92,72.19,74.46)
Solution()=Multiple_regression(DataX, DataY)
Print "Solutions:"
Print $("0.0000000"), Solution()
}
Task_Multiple_regression