you have been very useful to me so far, I hope you can help me deal with this. I am building a project that performs calculations with complex matrices. I used mikera / core.matrix.complex which uses mikera / core.matrix for matrix material and complex.core for determining complex numbers in clojure.
I want to be able to do any arithmetic, including using irrational numbers such as e (def e (Math/E))
and pi (def pi (Math/PI))
, and include matrix math, which may or may not be complicated. The problem arises when I mix functions from different libraries.
Right now my namespace is as follows:
(ns qgame.utils.math (:require [clojure.walk :as w :refer [postwalk prewalk]] [clojure.core.matrix :as mat] [clojure.core.matrix.complex :as compl] [incanter.core :as ic] [complex.core :as c :refer [+ - / *]]))
If I do (mat/mmul matrix1 matrix2)
, then everything is treated as a regular number, and using complex numbers will ruin it. I get a lot of ClassCastException org.apache.commons.math3.complex.Complex cannot be cast to java.lang.Number
. If I just require core.matrix.complex without requiring core.matrix, then none of the matrix functions work.
The same goes for things like (+ 3 4)
. If I directly (use 'complex.core)
in repl, then this will be evaluated as (7.0, 0.0)
, which is what I want, otherwise it will turn out as 7.
It seems to me that I am making it more complicated than that, core.matrix.complex looks like it has extensions for everything in core.matrix and clojure.core, but it does not use it with the namespace declaration that I have there is. I am not familiar with Clojure protocols, so I am definitely missing something. I just want all three libraries to be included, and that all math should be done in the context of complex numbers, i.e. 1 = (1.0, 0.0) and (Math/exp (* pi (complex 0 1)) => (-1.0, 0.0)
How can i do this? Sorry, if I am not clear, I will try to sort out any questions that I ask.
Edit: I was thinking about a problem, and actually the best place to start is the last equation I listed: Getting e ^ pi * I equal -1. If I try to use Math / exp with complex numbers, I get a casting exception.