Polynomial regression: Difference between revisions
Content added Content deleted
m (→{{header|PARI/GP}}: use degree instead of degree+1) |
(Perl 6 solution) |
||
Line 997: | Line 997: | ||
1 6 17 34 57 86 121 162 209 262 321 |
1 6 17 34 57 86 121 162 209 262 321 |
||
An approximating polynomial for your dataset is 3x^2 + 2x + 1. |
An approximating polynomial for your dataset is 3x^2 + 2x + 1. |
||
</pre> |
|||
=={{header|Perl 6}}== |
|||
We'll use a Clifford algebra library. |
|||
<lang perl6>use Clifford; |
|||
constant @x1 = <0 1 2 3 4 5 6 7 8 9 10>; |
|||
constant @y = <1 6 17 34 57 86 121 162 209 262 321>; |
|||
constant $x0 = [+] @e[^@x1]; |
|||
constant $x1 = [+] @x1 Z* @e; |
|||
constant $x2 = [+] @x1 »**» 2 Z* @e; |
|||
constant $y = [+] @y Z* @e; |
|||
my $J = $x1 ∧ $x2; |
|||
my $I = $x0 ∧ $J; |
|||
my $I2 = ($I·$I.reversion).Real; |
|||
.say for |
|||
(($y ∧ $J)·$I.reversion)/$I2, |
|||
(($y ∧ ($x2 ∧ $x0))·$I.reversion)/$I2, |
|||
(($y ∧ ($x0 ∧ $x1))·$I.reversion)/$I2;</lang> |
|||
{{out}} |
|||
<pre>1 |
|||
2 |
|||
3 |
|||
</pre> |
</pre> |
||