Inverting a symbolic matrix with Julia
Asked Answered
T

1

5

I am using the Symbolics.jl package and trying to invert a matrix. However, the output is giving 'true' instead of 1. Here is the code:

using Symbolics

@variables x

 mat=[x 0 0

       0 x 0

       0 0 x]

And the result I get is

 inv(mat)= [true / x   0      0

               0   true / x    0

               0     0       true / x]

Any thought on why this is happening?

Tannate answered 27/5, 2022 at 17:22 Comment(1)
That looks like the correct inverse. What's the issue?Curia
T
6

First of, this is not wrong as inv(mat) * mat will still give you the identity matrix. the problem is that the identity matrix in Num (the data type representing Symbolic.jl's variable is the diagonal matrix with true in its diagonal. This can be checked by looking at Matrix{Num}(I, 3, 3).

The inverse is calculated by solving the system AX = I and the true is created when the dense identity matrix is created.

This is due to the definition of I, namely const I = UniformScaling(true). My guess (and correct me if i'm wrong) is that this is for maximum compatibility. Normally this gets translated to a 1 in integer types but Num is an exception.

Taxiplane answered 27/5, 2022 at 17:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.