Vector products: Difference between revisions
Added Arturo implementation
Not a robot (talk | contribs) (Add Cowgol) |
Drkameleon (talk | contribs) (Added Arturo implementation) |
||
Line 578:
a x d = Dot product not defined for vectors of differing dimension.
a . (b x d) = Cross product is defined only for 3d vectors</pre>
=={{header|Arturo}}==
<lang rebol>; dot product
dot: function [a b][
sum map combine a b => product
]
; cross product
cross: function [a b][
A: (a\1 * b\2) - a\2 * b\1
B: (a\2 * b\0) - a\0 * b\2
C: (a\0 * b\1) - a\1 * b\0
@[A B C]
]
; scalar triple product
stp: function [a b c][
dot a cross b c
]
; vector triple product
vtp: function [a b c][
cross a cross b c
]
; task
a: [3 4 5]
b: [4 3 5]
c: @[neg 5 neg 12 neg 13]
print ["a • b =", dot a b]
print ["a x b =", cross a b]
print ["a • (b x c) =", stp a b c]
print ["a x (b x c) =", vtp a b c]</lang>
{{out}}
<pre>a • b = 49
a x b = [5 5 -7]
a • (b x c) = 6
a x (b x c) = [-267 204 -3]</pre>
=={{header|AutoHotkey}}==
|