Reputation: 579
let matrix = simd_double4x4([[10.0, 8.0, 7.0, 8.0], [10.0, 9.0, 19.0, 9.0], [8.0, 7.0, 10.0, 8.0], [8.0, 7.0, 10.0, 8.0]])
let rhs = SIMD4<Double>(100.0, 130.0, 120.0, 120.0)
let result = simd_mul(matrix.inverse, rhs)
print(result)
this code works for 2x2 and 3x3 matrices to solve the equation. but when it comes the 4x4 matrix I can't get result. and when I enter same values to a website for 4x4 equation solver I get the result but in swift I can not get it and it just prints -> SIMD4(-nan, -nan, -nan, -nan)
Upvotes: 1
Views: 1206
Reputation: 21956
The result is correct. It’s impossible to invert that particular matrix of yours, the determinant is zero.
Change the last row into something like 8.0, 7.0, 10.0, 9.0
and retry.
Here’s an output of some online calculator.
Upvotes: 3