kyonifer / koma

A scientific computing library for Kotlin. https://kyonifer.github.io/koma
Other
270 stars 23 forks source link

Equivalent of np.linalg.solve ? #106

Closed co-ord closed 3 years ago

co-ord commented 3 years ago

Hi,

I am desperately trying to solve a linear matrix equation using EJML

In Python I used to call the np.linalg.solve() function with 2 matrices A and B as parameters.

Example:

A = np.array([[3.001, 0.0, -1.0, -1.0, 0.0, 0.0, -1.0],
              [0.0, 3.001, 0.0, -1.0, -1.0, -1.0, 0.0],
              [-1.0, 0.0, 4.001, -1.0, -1.0, 0.0, -1.0],
              [-1.0, -1.0, -1.0, 5.001, -1.0, -1.0, 0.0],
              [ 0.0, -1.0, -1.0, -1.0, 3.001, 0.0, 0],
              [ 0.0, -1.0, 0.0, -1.0, 0.0, 2.001,  0],
              [-1.0, 0.0, -1.0, 0, 0, 0, 2.001]])

B = np.array([2.0, 0.0, 0.0, 0.0, -2.0, 0.0, 0.0])

solution = np.linalg.solve(A, B) 

print(solution)
--> array([ 0.837, -0.357,  0.115, -0.079, -0.773, -0.218,  0.476])

However with EJML, SimpleMatrix solution = A.solve(B); returns the following message Unexpected dimensions for X: X rows = 7 expected = 7

Am I forgetting something ?