How to find out if the Sympy variable is complex?

后端 未结 1 1245
谎友^
谎友^ 2021-01-23 06:06

I am writing a code which involves solving this equation

X = solve(Theta_Mod_Eqn*Ramp_Equation/(x+PT) - C, x)

I am using sympy library, now the

相关标签:
1条回答
  • 2021-01-23 06:16

    The set of real numbers is a subset of the set of complex numbers. So, every real number is a complex number. For example, 3 is a complex number.

    The correct question to ask is how to find out if a root is real. For that, you can use i.is_real if i is a SymPy symbol:

    for i in X:
        if i.is_real:
            if (i>-0.01 and i<maxSheaveDisp):
                A = i
    

    One can also compare im(i) to 0: if im(i) == 0. This works for Python floats too.

    0 讨论(0)
提交回复
热议问题