Polynomial regression: Difference between revisions

no edit summary
m (J (added a space so Y=: is easier to see)
No edit summary
Line 395:
<lang haskell>*Main> polyfit 3 [1,6,17,34,57,86,121,162,209,262,321]
[1.0,2.0,3.0]</lang>
 
 
=={{header|HicEst}}==
<lang hicest>REAL :: n=10, x(n), y(n), m=3, p(m)
 
x = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
y = (1, 6, 17, 34, 57, 86, 121, 162, 209, 262, 321)
 
p = 2 ! initial guess for the polynom's coefficients
 
SOLVE(NUL=Theory()-y(nr), Unknown=p, DataIdx=nr, Iters=iterations)
 
WRITE(ClipBoard, Name) p, iterations
 
FUNCTION Theory()
! called by the solver of the SOLVE function. All variables are global
Theory = p(1)*x(nr)^2 + p(2)*x(nr) + p(3)
END</lang>
<lang hicest>SOLVE performs a (nonlinear) least-square fit (Levenberg-Marquardt):
p(1)=2.997135145; p(2)=2.011348347; p(3)=0.9906627242; iterations=19;</lang>
 
=={{header|J}}==
Anonymous user