Vector products: Difference between revisions
Rename Perl 6 -> Raku, alphabetize, minor clean-up
m (→{{header|Factor}}: whitespace/style tweaks) |
Thundergnat (talk | contribs) (Rename Perl 6 -> Raku, alphabetize, minor clean-up) |
||
Line 861:
a x (b x c) = {-267, 204, -3}
</pre>
=={{header|Erlang}}==
<lang Erlang>
Line 885 ⟶ 886:
io:fwrite("~p,~p,~p~n",vector_product(C,vector_product(A,B))).
</lang>
=={{header|ERRE}}==
<lang ERRE>
Line 1,355 ⟶ 1,357:
}
</lang>
=={{header|Go}}==
<lang go>package main
Line 1,813 ⟶ 1,816:
scalar product =:6
triple product =:[-267,204,-3]</pre>
=={{header|JavaScript}}==
===ES5===
Line 3,036 ⟶ 3,040:
(3 4 5) . ((4 3 5) x (-5 -12 -13)) = 6
(3 4 5) x ((4 3 5) x (-5 -12 -13)) = (-267 204 -3)</pre>
=={{header|Perl 6}}==▼
{{Works with|rakudo|2015-11-24}}▼
<lang perl6>sub infix:<⋅> { [+] @^a »*« @^b }▼
sub infix:<⨯>([$a1, $a2, $a3], [$b1, $b2, $b3]) {▼
[ $a2*$b3 - $a3*$b2,▼
$a3*$b1 - $a1*$b3,▼
$a1*$b2 - $a2*$b1 ];▼
}▼
sub scalar-triple-product { @^a ⋅ (@^b ⨯ @^c) }▼
sub vector-triple-product { @^a ⨯ (@^b ⨯ @^c) }▼
my @a = <3 4 5>;▼
my @b = <4 3 5>;▼
my @c = <-5 -12 -13>;▼
say (:@a, :@b, :@c);▼
say "a ⋅ b = { @a ⋅ @b }";▼
say "a ⨯ b = <{ @a ⨯ @b }>";▼
say "a ⋅ (b ⨯ c) = { scalar-triple-product(@a, @b, @c) }";▼
say "a ⨯ (b ⨯ c) = <{ vector-triple-product(@a, @b, @c) }>";</lang>▼
{{out}}▼
<pre>("a" => ["3", "4", "5"], "b" => ["4", "3", "5"], "c" => ["-5", "-12", "-13"])▼
a ⋅ b = 49▼
a ⨯ b = <5 5 -7>▼
a ⋅ (b ⨯ c) = 6▼
a ⨯ (b ⨯ c) = <-267 204 -3></pre>▼
=={{header|Phix}}==
Line 3,630 ⟶ 3,605:
(printf "A x B x C = ~s\n" (vector-triple-product A B C))
</lang>
(formerly Perl 6)
▲{{Works with|rakudo|2015-11-24}}
▲<lang perl6>sub infix:<⋅> { [+] @^a »*« @^b }
▲sub infix:<⨯>([$a1, $a2, $a3], [$b1, $b2, $b3]) {
▲ [ $a2*$b3 - $a3*$b2,
▲ $a3*$b1 - $a1*$b3,
▲ $a1*$b2 - $a2*$b1 ];
▲}
▲sub scalar-triple-product { @^a ⋅ (@^b ⨯ @^c) }
▲sub vector-triple-product { @^a ⨯ (@^b ⨯ @^c) }
▲my @a = <3 4 5>;
▲my @b = <4 3 5>;
▲my @c = <-5 -12 -13>;
▲say (:@a, :@b, :@c);
▲say "a ⋅ b = { @a ⋅ @b }";
▲say "a ⨯ b = <{ @a ⨯ @b }>";
▲say "a ⋅ (b ⨯ c) = { scalar-triple-product(@a, @b, @c) }";
▲say "a ⨯ (b ⨯ c) = <{ vector-triple-product(@a, @b, @c) }>";</lang>
▲{{out}}
▲<pre>("a" => ["3", "4", "5"], "b" => ["4", "3", "5"], "c" => ["-5", "-12", "-13"])
▲a ⋅ b = 49
▲a ⨯ b = <5 5 -7>
▲a ⋅ (b ⨯ c) = 6
▲a ⨯ (b ⨯ c) = <-267 204 -3></pre>
=={{header|REXX}}==
Line 4,143 ⟶ 4,148:
0 OK, 0:1370</pre>
=={{header|VBA}}==
{{trans|Phix}}<lang vb>Option Base 1
Line 4,174 ⟶ 4,180:
a . (b x c) = 6
a x (b x c) = (-267, 204, -3)</pre>
=={{header|Visual Basic .NET}}==
Class: Vector3D
|