Vector products: Difference between revisions

Content added Content deleted
m (→‎{{header|Factor}}: whitespace/style tweaks)
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 861: Line 861:
a x (b x c) = {-267, 204, -3}
a x (b x c) = {-267, 204, -3}
</pre>
</pre>

=={{header|Erlang}}==
=={{header|Erlang}}==
<lang Erlang>
<lang Erlang>
Line 885: Line 886:
io:fwrite("~p,~p,~p~n",vector_product(C,vector_product(A,B))).
io:fwrite("~p,~p,~p~n",vector_product(C,vector_product(A,B))).
</lang>
</lang>

=={{header|ERRE}}==
=={{header|ERRE}}==
<lang ERRE>
<lang ERRE>
Line 1,355: Line 1,357:
}
}
</lang>
</lang>

=={{header|Go}}==
=={{header|Go}}==
<lang go>package main
<lang go>package main
Line 1,813: Line 1,816:
scalar product =:6
scalar product =:6
triple product =:[-267,204,-3]</pre>
triple product =:[-267,204,-3]</pre>

=={{header|JavaScript}}==
=={{header|JavaScript}}==
===ES5===
===ES5===
Line 3,036: Line 3,040:
(3 4 5) . ((4 3 5) x (-5 -12 -13)) = 6
(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>
(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}}==
=={{header|Phix}}==
Line 3,630: Line 3,605:
(printf "A x B x C = ~s\n" (vector-triple-product A B C))
(printf "A x B x C = ~s\n" (vector-triple-product A B C))
</lang>
</lang>

=={{header|Raku}}==
(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}}==
=={{header|REXX}}==
Line 4,143: Line 4,148:


0 OK, 0:1370</pre>
0 OK, 0:1370</pre>

=={{header|VBA}}==
=={{header|VBA}}==
{{trans|Phix}}<lang vb>Option Base 1
{{trans|Phix}}<lang vb>Option Base 1
Line 4,174: Line 4,180:
a . (b x c) = 6
a . (b x c) = 6
a x (b x c) = (-267, 204, -3)</pre>
a x (b x c) = (-267, 204, -3)</pre>

=={{header|Visual Basic .NET}}==
=={{header|Visual Basic .NET}}==
Class: Vector3D
Class: Vector3D