Talk:Polynomial regression: Difference between revisions
Content added Content deleted
m (moved Talk:Polynomial Fitting to Talk:Polynomial regression) |
|||
Line 7: | Line 7: | ||
==About fortran== |
==About fortran== |
||
It is quickly coded, and while trying to remember things. It works anyway, but I suppose there's a better way. the method I've followed is straightforwardly from [http://mathworld.wolfram.com/LeastSquaresFittingPolynomial.html Wolfram.com] --[[User:ShinTakezou|ShinTakezou]] 23:58, 18 December 2008 (UTC) |
It is quickly coded, and while trying to remember things. It works anyway, but I suppose there's a better way. the method I've followed is straightforwardly from [http://mathworld.wolfram.com/LeastSquaresFittingPolynomial.html Wolfram.com] --[[User:ShinTakezou|ShinTakezou]] 23:58, 18 December 2008 (UTC) |
||
---- |
|||
Good work with the Fortran routine. However, the scaling of the independent variable is missing without which the fitting will fail in many cases. For this purpose one needs the ''mean'' and ''standard deviation'' of the independent variable (vx in the code). Now scale vx to vxcopy and do everything using vxcopy. The code should be changed as follows. I am using this modified version for big applications in my work. |
|||
allocate(ipiv(n)) |
|||
allocate(work(lwork)) |
|||
allocate(XT(n, size(vx))) |
|||
allocate(X(size(vx), n)) |
|||
allocate(XTX(n, n)) |
|||
vxcopy = vx !=== make a copy of the independent variable |
|||
mu = stdmean(size(vxcopy), vxcopy) !=== call the function stdmean and get mu(1) - mean, mu(2) - standard deviation |
|||
vxcopy = (vxcopy - mu(1)) / mu(2) !=== scale the coordinates |
|||
! prepare the matrix |
|||
do i = 0, d |
|||
do j = 1, size(vx) |
|||
X(j, i+1) = vxcopy(j)**i !=== do the rest with vxcopy |
|||
end do |
|||
end do |
|||
--[[User:Raghu|Raghu]] 12:31, 12 July 2011 (UTC) |