- We wish to fit the general least square model

to a set of paired observations.
- The paired observations are

- Defining

- Construct the matrix

- Calculate the coefficients in the least square model by solving

where

- Pseudo-code to Assemble the Equations for General Least Square
nbasis = no. of basis functions
ndata = no. of paired observations
-----Program to create the linear system of equations
DO irow = 1 to ndata
     CALL Basis ( x ( irow ) , z , nbasis)
     c ( irow ) = y ( irow )
     DO jcol = 1 to nbasis
         ZM ( irow , jcol ) = z ( jcol )
     END DO
END DO
DO irow = 1 to nbasis
     DO jcol = 1 to ndata
         ZT ( irow , jcol ) = ZM ( jcol , irow )
     END DO
END DO
DO i = 1 , nbasis
     DO j = 1 , nbasis
         ZZT ( i , j ) = 0.0
         DO k = 1 , ndata
             ZZT ( i , j ) = ZT ( i , k ) * ZM ( k , j ) + ZZT ( i , j )
         END DO
     END DO
END DO
DO i = 1 , nbasis
     Zy ( i ) = 0.0
     DO k = 1 , ndata
         Zy ( i ) = ZT ( i , k ) * c ( k ) + Zy ( i )
     END DO
END DO
Solve [ZZT]{A} = {Zy} do obtain the coefficients in the general expansion.
-----Program for Basis Functions
SUBROUTINE Basis( x , z , nbasis )
Dimension z ( nbasis )
z ( 1 ) = basis function #1
z ( 2 ) = basis function #2
...
...
z ( nbasis ) = basis function #nbasis
|