These calculations can be made much faster in SymPy. These are only
2x2 matrices so I would just take the basic formula for the inverse of
a 2x2 matrix and sub into that:
In [20]: Matrix([[x, y], [z, t]]).inv()
Out[20]:
⎡ t -y ⎤
⎢───────── ─────────⎥
⎢t⋅x - y⋅z t⋅x - y⋅z⎥
⎢ ⎥
⎢ -z x ⎥
⎢───────── ─────────⎥
⎣t⋅x - y⋅z t⋅x - y⋅z⎦
The denominator can be factored out of the calculation. I expect that
you can make something work in SymPy here in a way that is much easier
than trying to use C/autowrap.
Yes, SymPy should be faster at handling this. I tried your code and I
found that it hung in equals. I think that's a bug that is already
reported:
https://github.com/sympy/sympy/issues/14675
Here's your code (including the necessary symbol definitions - please
include those!):
from sympy import *
rb, rc, rg, rs, rd, w, cb, cc, lg, ld, ls = symbols('rb, rc, rg, rs,
rd, w, cb, cc, lg, ld, ls')
Yint = Matrix([[2/rb + I*w*2*cb, -1/rb - I*w*cb], [-1/rb - I*w*cb,
1/rb + 1/rc +I*w*(cb + cc)]])
Zint = Yint.inv()
Zext = Matrix([[rg + rs + I*w*(lg + ls), rs + I*w*ls],[rs + I*w*ls, rd
+ rs + I*w*(ld + ls)]])
Z = Zext + Zint
Y = Z.inv()
Yre =
sympy.re(Y)
Yim =
sympy.im(Y)
err = (Yre_me - Yre)**2 + (Yim_me - Yim)**2
--
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+un...@googlegroups.com.
> To view this discussion on the web visit
https://groups.google.com/d/msgid/sympy/b081b222-e4f7-40d4-ae7e-ed0e6bacd65b%40googlegroups.com.