Vector products: Difference between revisions
Content added Content deleted
m (No longer needs to be a function.) |
(→{{header|Clojure}}: added Clojure solution) |
||
Line 289: | Line 289: | ||
a . b x c : 6 |
a . b x c : 6 |
||
a x b x c : ( -267 , 204 , -3 ) |
a x b x c : ( -267 , 204 , -3 ) |
||
</PRE> |
|||
=={{header|Clojure}}== |
|||
<lang clojure> |
|||
(defrecord Vector [x y z]) |
|||
(defn dot |
|||
[U V] |
|||
(+ (* (:x U) (:x V)) |
|||
(* (:y U) (:y V)) |
|||
(* (:z U) (:z V)))) |
|||
(defn cross |
|||
[U V] |
|||
(new Vector |
|||
(- (* (:y U) (:z V)) (* (:z U) (:y V))) |
|||
(- (* (:z U) (:x V)) (* (:x U) (:z V))) |
|||
(- (* (:x U) (:y V)) (* (:y U) (:x V))))) |
|||
(let [a (new Vector 3 4 5) |
|||
b (new Vector 4 3 5) |
|||
c (new Vector -5 -12 -13)] |
|||
(doseq |
|||
[prod (list |
|||
(dot a b) |
|||
(cross a b) |
|||
(dot a (cross b c)) |
|||
(cross a (cross b c)))] |
|||
(println prod))) |
|||
</lang> |
|||
Output: |
|||
<PRE> |
|||
49 |
|||
#:user.Vector{:x 5, :y 5, :z -7} |
|||
6 |
|||
#:user.Vector{:x -267, :y 204, :z -3} |
|||
</PRE> |
</PRE> |
||