2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
|
|
@ -1,11 +1,11 @@
|
|||
Find an approximating polynom of known degree for a given data.
|
||||
Find an approximating polynomial of known degree for a given data.
|
||||
|
||||
Example:
|
||||
For input data:
|
||||
x = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
|
||||
y = {1, 6, 17, 34, 57, 86, 121, 162, 209, 262, 321};
|
||||
The approximating polynom is:
|
||||
The approximating polynomial is:
|
||||
3 x<sup>2</sup> + 2 x + 1
|
||||
Here, the polynom's coefficients are (3, 2, 1).
|
||||
Here, the polynomial's coefficients are (3, 2, 1).
|
||||
|
||||
This task is intended as a subtask for [[Measure relative performance of sorting algorithms implementations]].
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ bool polynomialfit(int obs, int degree,
|
|||
cov = gsl_matrix_alloc(degree, degree);
|
||||
|
||||
for(i=0; i < obs; i++) {
|
||||
gsl_matrix_set(X, i, 0, 1.0);
|
||||
for(j=0; j < degree; j++) {
|
||||
gsl_matrix_set(X, i, j, pow(dx[i], j));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
X=:i.# Y=:1 6 17 34 57 86 121 162 209 262 321
|
||||
Y (%. (^/ x:@i.@#)) X
|
||||
Y=:1 6 17 34 57 86 121 162 209 262 321
|
||||
(%. ^/~@x:@i.@#) Y
|
||||
1 2 3 0 0 0 0 0 0 0 0
|
||||
|
|
|
|||
|
|
@ -1,2 +1,2 @@
|
|||
Y (%. (i.3) ^/~ ]) X
|
||||
Y %. (i.3) ^/~ i.#Y
|
||||
1 2 3
|
||||
|
|
|
|||
|
|
@ -1,2 +1,2 @@
|
|||
lsf(X,Y,n)=my(M=matrix(#X,n,i,j,X[i]^(j-1))); Polrev(matsolve(M~*M,M~*Y~)
|
||||
lsf([0..10], [1,6,17,34,57,86,121,162,209,262,321], 3)
|
||||
lsf(X,Y,n)=my(M=matrix(#X,n+1,i,j,X[i]^(j-1))); Polrev(matsolve(M~*M,M~*Y~))
|
||||
lsf([0..10], [1,6,17,34,57,86,121,162,209,262,321], 2)
|
||||
|
|
|
|||
20
Task/Polynomial-regression/Perl-6/polynomial-regression.pl6
Normal file
20
Task/Polynomial-regression/Perl-6/polynomial-regression.pl6
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
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;
|
||||
Loading…
Add table
Add a link
Reference in a new issue