Hmm, the last column of your martrix is zero, so it cannot be inverted 
because its determiant (e.det()) is zero.  So how would Mathematica be able 
to calculate an inverse?

gerardo...@gmail.com schrieb am Dienstag, 11. Januar 2022 um 13:30:02 UTC+1:

> Sure, sorry  about the image, I was unaware of how easy is to generate 
> python code with the print methods
>
> from sympy import Symbol, Matrix,I
> gamma_c = Symbol('gamma_c')
> n_c = Symbol('n_c')
> gamma_h = Symbol('gamma_h')
> n_h = Symbol('n_h')
> epsilon_c = Symbol('epsilon_c')
> g = Symbol('g')
> epsilon_h = Symbol('epsilon_h')
> e = Matrix([[-gamma_c*(n_c + 1) - gamma_h*(n_h + 1), 0, 0, 0, 0, 
> gamma_c*n_c, 0, 0, 0, 0, gamma_h*n_h, 0, 0, 0, 0, 0], [0, -I*epsilon_c - 
> gamma_c*n_c/2 - gamma_c*(n_c + 1)/2 - gamma_h*(n_h + 1), I*g, 0, 0, 0, 0, 
> 0, 0, 0, 0, gamma_h*n_h, 0, 0, 0, 0], [0, I*g, -I*epsilon_h - gamma_c*(n_c 
> + 1) - gamma_h*n_h/2 - gamma_h*(n_h + 1)/2, 0, 0, 0, 0, gamma_c*n_c, 0, 0, 
> 0, 0, 0, 0, 0, 0], [0, 0, 0, -gamma_c*n_c/2 - gamma_c*(n_c + 1)/2 - 
> gamma_h*n_h/2 - gamma_h*(n_h + 1)/2 - I*(epsilon_c + epsilon_h), 0, 0, 0, 
> 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, -gamma_c*n_c/2 - gamma_c*(n_c + 
> 1)/2 - gamma_h*(n_h + 1) - I*(epsilon_h - (epsilon_c + epsilon_h)), 0, 0, 
> 0, -I*g, 0, 0, 0, 0, 0, gamma_h*n_h, 0], [gamma_c*(n_c + 1) - gamma_h*n_h, 
> 0, 0, 0, 0, -gamma_c*n_c - gamma_h*n_h - gamma_h*(n_h + 1), I*g, 0, 0, 
> -I*g, -gamma_h*n_h, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, I*g, -gamma_c*n_c/2 - 
> gamma_c*(n_c + 1)/2 - gamma_h*n_h/2 - gamma_h*(n_h + 1)/2 - I*(-epsilon_c + 
> epsilon_h), 0, 0, 0, -I*g, 0, 0, 0, 0, 0], [0, 0, gamma_c*(n_c + 1), 0, 0, 
> 0, 0, -I*epsilon_h - gamma_c*n_c - gamma_h*n_h/2 - gamma_h*(n_h + 1)/2, 0, 
> 0, 0, -I*g, 0, 0, 0, 0], [0, 0, 0, 0, -I*g, 0, 0, 0, -gamma_c*(n_c + 1) - 
> gamma_h*n_h/2 - gamma_h*(n_h + 1)/2 - I*(epsilon_c - (epsilon_c + 
> epsilon_h)), 0, 0, 0, 0, gamma_c*n_c, 0, 0], [0, 0, 0, 0, 0, -I*g, 0, 0, 0, 
> -gamma_c*n_c/2 - gamma_c*(n_c + 1)/2 - gamma_h*n_h/2 - gamma_h*(n_h + 1)/2 
> - I*(epsilon_c - epsilon_h), I*g, 0, 0, 0, 0, 0], [-gamma_c*n_c + 
> gamma_h*(n_h + 1), 0, 0, 0, 0, -gamma_c*n_c, -I*g, 0, 0, I*g, -gamma_c*n_c 
> - gamma_c*(n_c + 1) - gamma_h*n_h, 0, 0, 0, 0, 0], [0, gamma_h*(n_h + 1), 
> 0, 0, 0, 0, 0, -I*g, 0, 0, 0, -I*epsilon_c - gamma_c*n_c/2 - gamma_c*(n_c + 
> 1)/2 - gamma_h*n_h, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
> -gamma_c*n_c/2 - gamma_c*(n_c + 1)/2 - gamma_h*n_h/2 - gamma_h*(n_h + 1)/2 
> + I*(epsilon_c + epsilon_h), 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 
> gamma_c*(n_c + 1), 0, 0, 0, 0, I*epsilon_h - gamma_c*n_c - gamma_h*n_h/2 - 
> gamma_h*(n_h + 1)/2, I*g, 0], [0, 0, 0, 0, gamma_h*(n_h + 1), 0, 0, 0, 0, 
> 0, 0, 0, 0, I*g, I*epsilon_c - gamma_c*n_c/2 - gamma_c*(n_c + 1)/2 - 
> gamma_h*n_h, 0], [gamma_c*n_c + gamma_h*n_h, 0, 0, 0, 0, gamma_c*n_c + 
> gamma_h*n_h + gamma_h*(n_h + 1), 0, 0, 0, 0, gamma_c*n_c + gamma_c*(n_c + 
> 1) + gamma_h*n_h, 0, 0, 0, 0, 0]])
>
> However, I care more about how to speed up matrix inversion in general, as 
> it was terribly fast in Mathematica and it never finished in sympy. I guess 
> there is a more efficient way than using 
>
> e.inv()
> El martes, 11 de enero de 2022 a las 3:21:33 UTC+1, Oscar escribió:
>
>> On Monday, 10 January 2022 at 15:51:49 UTC gerardo...@gmail.com wrote:
>>
>>> Hi, 
>>>
>>> So I was working in some problem and I had to switch to mathematica due 
>>> to the time the inverse of a matrix was taking, in mathematica it was 
>>> solved in less than a second while the computation in sympy has been 
>>> running for a day and hasn't finished.
>>>
>>> Is there anyway to speed up matrix inversion in sympy?
>>>
>>> Given that it is so much faster in mathematica is there any interest in 
>>> implementing some method (maybe theirs) that yields the inverse of a matrix 
>>> faster? if so I'd like to do it maybe someone could give me some pointers 
>>> to get me started 
>>>
>>> The matrix  is 15*15 and attached as an image, but any example of how to 
>>> speed things up will do. Thanks a lot!
>>>
>>
>> The image is not a useful way to share this. Can you show simple code to 
>> make this matrix? 
>>
>> (i.e. just the code to make the symbols and then something like the 
>> repr() of the matrix but make sure it's fully runnable code without any 
>> missing bits)
>>
>> --
>> Oscar
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sympy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/37a7e8b1-1523-463b-bdfa-26ca1e73a247n%40googlegroups.com.

Reply via email to