Original Question:
To find the equation of the parabola
y = A + Bx + Cx^2
that best fits a set of n data points, the values of A, B, and C must be determined for which the sum of the squares of the deviations of the observed y-values from the predicted y-values using the equation) is as small as possible. These values are found by solving the linear system:
nA + (Ex)B + (E(x^2))C = Ey
(Ex)A + (Ex^2)B + (Ex^3)C = E(xy)
(Ex^2)A + (Ex^3)B + (Ex^4)C = E((x^2)y)
E = sumation notaion = capital sigma
Find the equation of the least-squares parabola for the following set of data points:
DATA X / 0.05, 0.12, 0.15, 0.30, 0.45, 0.70, 0.84, 1.04 /
DATA Y / 0.957,0.851,0.832,0.720,0.583,0.378,0.295,0.156 /
I'm getting a couple errors in my code and I'm just not quite sure where I'm going wrong. I hand calculated the "Data Weights (A, B, C)" from the system of linear equations.
The Error Log is:
--------------------Configuration: FIT - Win32 Debug--------------------
Compiling Fortran...
C:\MSDEV\FIT.f90
C:\MSDEV\FIT.f90(34): warning FOR4265: symbol M referenced but not set
Linking...
FIT.obj : error LNK2001: unresolved external symbol _GAUSS@24
FIT.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
FIT.exe - 2 error(s), 1 warning(s)
This is my current program code:
PROGRAM FIT
REAL X(8),Y(8),LIN,QUAD,WEIGHTS(3)
EXTERNAL LIN,QUAD
DATA X / 0.05, 0.12, 0.15, 0.30, 0.45, 0.70, 0.84, 1.04 /
DATA Y / 0.957,0.851,0.832,0.720,0.583,0.378,0.295,0.156 /
DATA WEIGHTS / -0.245866582919757, 4.19120539122495, 3.92469397298994 /
CALL GENLSQ(X,Y,8,LIN,QUAD,WEIGHTS)
PRINT *,'THE WEIGHTS ARE'
PRINT *, WEIGHTS
STOP
END
SUBROUTINE GENLSQ(X,Y,N,F,G,WEIGHTS)
INTEGER N
REAL X(N), Y(N), MATRIX(3,4),WEIGHTS(3)
EXTERNAL F,G
DATA MATRIX / 12*0.0 /
MATRIX(1,1) = FLOAT(N)
DO 1 I = 1, M
MATRIX(1,2) = MATRIX(1,2) + F(X(I))
MATRIX(1,3) = MATRIX(1,3) + G(X(I))
MATRIX(1,4) = MATRIX(1,4) + Y(I)
MATRIX(2,2) = MATRIX(2,2) + F(X(I)) ** 2
MATRIX(2,3) = MATRIX(2,3) + F(X(I))*G(X(I))
MATRIX(2,4) = MATRIX(2,4) + F(X(I))*Y(I)
MATRIX(3,3) = MATRIX(3,3) + G(X(I)) ** 2
MATRIX(3,4) = MATRIX(3,4) + G(X(I))*Y(I)
1 CONTINUE
MATRIX(2,1) = MATRIX(1,2)
MATRIX(3,1) = MATRIX(1,3)
MATRIX(3,2) = MATRIX(2,3)
CALL GAUSS(MATRIX,3,4,3,WEIGHTS,SINGUL)
RETURN
END
REAL FUNCTION LIN(X)
LIN=X
RETURN
END
REAL FUNCTION QUAD(X)
QUAD=X*X
RETURN
END
ANY and ALL help is much appreciated! Thanks, Joe