I'm new to clojure and I am trying to make a small program that does math with complex numbers. I've tried multiple versions of the multiply function and they all give the same error. For some other functions, using let fixed it but not here. im-make just returns a vector with the real and imaginary numbers.
(defn im-mult
([i j]
(let [a (first i)
b (second i)
x (first j)
y (second j)]
(im-make (- (* (a) (b)) (* (x) (y)))
(+ (* (a) (b)) (* (x) (y)))))))
given two vectors with a real and imaginary number, => (im-mult x y)
ClassCastException java.lang.Long cannot be cast to clojure.lang.IFn ComplexMath.core/im-mult (NO_SOURCE_FILE:7)
I just want to say, wow! Didn't think clojure had this much backing around here, thanks for the suggestions, the error was of course parenthesis and incorrect multiplying.
z1 = (a + bi)
,z2 = (c + di)
, their product isz1 * z2 = (ac-bd)+(ad+bc)i
. So, if (im-mult z1 z2) = z1 * z2, then(defn im-mult [[a b] [c d]] [(- (* a c) (* b d)), (+ (* a d) (* b c))])
. – A. Webb