Sympy: respect i^^2 = -1 in expansions

33 views Asked by At

When executing the following

from sympy import *

R, L, C, w = symbols("R L C w", real = True)
j = symbols("j", real = False)

H = (1 + j * w * C * R) * (j * w * L + R)
H = H.expand()

print(H)
print(latex(H))

the result is as stated below.

C*L*R*j**2*w**2 + C*R**2*j*w + L*j*w + R
C L R j^{2} w^{2} + C R^{2} j w + L j w + R

I want to set j^2 = -1 and j^3 = -j and so on, if necessary. How to do that in this calculation?

1

There are 1 answers

0
llf On BEST ANSWER

Sympy recognizes the imaginary constant as sympy.I.

>>> import sympy
>>> sympy.I**2
-1