Issue
I keep getting expressions like this image, despite declaring these symbols as reals.
The code to reproduce is:
import sympy as sp
delta = sp.Symbol('delta', real=True)
f = sp.sqrt(1/delta)
prod = sp.conjugate(f)*f
prod.subs(delta,delta)
I expected to get 1/delta
Also trying simplify()
does not work either.
Solution
According to the official SymPy Docs for conjugate
, it looks like the function is supposed to return the complex conjugate for its input. In other words, it takes the complex part of the number and flips the sign.
In your example, you are taking the square root of a variable. If delta = -1
, then the resulting conjugate could be unreal and thus different than if delta
was any other integer. Thus, SymPy
wraps the result in a conjugate
object.
If you want to tell Sympy that your variable delta
is positive (and thus f
must be real), then you should define it as delta = sp.Symbol('delta', real=True, positive=True)
.
Answered By - Akilan Manivannan
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.