sts
sts

Reputation: 51

Inverting a symbolic matrix with Julia

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?

Upvotes: 5

Views: 602

Answers (1)

Sobhan
Sobhan

Reputation: 333

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.

Upvotes: 6

Related Questions