Jump to content

Polynomial regression: Difference between revisions

added Ursala
(→‎{{header|TI-89 BASIC}}: add explanation)
(added Ursala)
Line 496:
 
Output: <code>3.·x<sup>2</sup> + 2.·x + 1.</code>
 
=={{header|Ursala}}==
{{libheader|LAPACK}}
The fit function defined below returns the coefficients of an nth-degree polynomial in order
of descending degree fitting the lists of inputs x and outputs y.
The real work is done by the dgelsd function from the lapack library.
Ursala provides a simplified interface to this library whereby the data
can be passed as lists rather than arrays, and all memory management is
handled automatically.
<lang Ursala>#import std
#import nat
#import flo
 
(fit "n") ("x","y") = ..dgelsd\"y" (gang \/*pow float*x iota successor "n")* "x"</lang>
test program:
<lang Ursala>x = <0.,1.,2.,3.,4.,5.,6.,7.,8.,9.,10.>
y = <1.,6.,17.,34.,57.,86.,121.,162.,209.,262.,321.>
 
#cast %eL
 
example = fit2(x,y)</lang>
output:
<pre><3.000000e+00,2.000000e+00,1.000000e+00></pre>
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.