Unitful.jl
Unitful.jl copied to clipboard
Broken Division of Matrix of Quantities by Matrix
using Unitful
A = randn((5,5))
B = randn((5,5))u"m"
A \ B
# ERROR: DimensionError: m and -0.914772091609924 are not dimensionally compatible.
This used to work (tested on Julia 1.6.7), but seems to be an issue with a change in LinearAlgebra as of 1.7.3. Presumably this is a change we can't do anything about upstream, but if there's a clean way of solving this in Unitful.jl, that could be helpful
´´´ julia> using LinearAlgebra julia> det(B) -14.351046206338994m⁵ ´´´
I'm not a matematician, but when a square, non-dimensionless matrix has a non-zero determinant like this, I believe the inverse always exist. But doesn't the determinant and inverse also exist if the dimensions are symmetric about the diagonal? E.g.
´´´ C = [1.0 2m;1m^-1 1] ´´´
However, we can't use ´det(C)´ to determine the existence of the inverse:
´´´
julia> det(C)
ERROR: ArgumentError: cannot reinterpret Unitfu.Quantity{Float64} as Float64, type Unitfu.Quantity{Float64} is not a bits type
´´´
If you agree that allowing illegal operations is not the way to go, are there better criteria than checking if the determinant exists? I believe implementing a unitful method for determinant may not be the best approach, because it is often not necessary to calculate the determinant at all when solving matrix equations.
Again, I'm not a matematician, but interested in the quality control and reassurance that unit checking potentially give.