User:Grondilu
My Favorite Languages | |
Language | Proficiency |
Perl 6 | ****. |
Perl | **... |
Bash | ***.. |
Octave | *.... |
Perl 6
We're going to solve the example on the Wikipedia article using Clifford, a geometric algebra module. Optimization for large vector space does not quite work yet, so it's going to take (a lof of) time and a fair amount of memory, but it should work.
Let's create four vectors containing our input data:
Then what we're looking for are three scalars , and such that:
To get for instance we can first make the and terms disappear:
Noting , we then get:
<lang perl6>use Clifford; my @height = <1.47 1.50 1.52 1.55 1.57 1.60 1.63 1.65 1.68 1.70 1.73 1.75 1.78 1.80 1.83>; my @weight = <52.21 53.12 54.48 55.84 57.20 58.57 59.93 61.29 63.11 64.47 66.28 68.10 69.92 72.19 74.46>;
my $w = [+] @weight Z* @e;
my $h0 = [+] @e[^@height]; my $h1 = [+] @height Z* @e; my $h2 = [+] (@height X** 2) Z* @e;
my $J = $h1∧$h2; my $I = $h0∧$J; say "alpha = ", ($w∧$J)·$I.reversion/($I·$I.reversion).Real;</lang>
- Output:
alphas = 128.81280357844