原始问题:
找出抛物线方程
y = A + Bx + Cx ^ 2
最适合一组n个数据点,必须确定A,B和C的值,使用该等式,观察到的y值与预测的y值的偏差的平方和)尽可能小。通过求解线性系统可以找到这些值:
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
找到以下数据点集的最小二乘抛物线方程:
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 /
我的代码中出现了一些错误,我不太确定我哪里出错了。我从线性方程组中计算出“数据权重(A,B,C)”。
错误日志是:
--------------------配置:FIT - Win32 Debug -------------------- < / p>
编译Fortran ......
C:\ MSDEV \ FIT.f90
C:\ MSDEV \ FIT.f90(34):警告FOR4265:符号M引用但未设置
...链接
FIT.obj:错误LNK2001:未解析的外部符号_GAUSS @ 24
FIT.exe:致命错误LNK1120:1个未解析的外部
执行link.exe时出错。
FIT.exe - 2个错误,1个警告
这是我目前的程序代码:
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
任何和所有帮助非常感谢! 谢谢, 乔
答案 0 :(得分:0)
C:\MSDEV\FIT.f90(34): warning FOR4265: symbol M referenced but not set
AFAICT,你永远不会定义你的循环限制M.这肯定会引起各种恶作剧。
答案 1 :(得分:0)
您最好使用implicit none
并将您的程序放入模块和use
该模块。而不是external
。第一个将导致编译器通知您未声明的变量。第二个将使编译器能够检查过程调用中参数的一致性。
module my_subs
implicit none
contains
SUBROUTINE GENLSQ
....
end SUBROUTINE GENLSQ
FUNCTION LIN(X)
real :: LIN
real, intent (in) :: x
LIN = X
end FUNCTION LIN(X)
FUNCTION QUAD(X)
real :: QUAD
real, intent (in) :: x
QUAD=X*X
end FUNCTION QUAD
end module my_subs
program fit
use my_subs
implicit none
.....
END program fit