Reputation: 916
I cannot figure it out how to assume positive real part of a complex number in Sympy. Example of an Mathematica code:
a = InverseFourierTransform[ R/(I omega - lambda) + Conjugate[R]/(I omega - Conjugate[lambda]), omega, t, FourierParameters -> {1, -1}]
Simplify[a, {Re[lambda] < 0, t > 0}]
Similar Sympy code:
import sympy as sym
sym.init_printing()
ω = sym.symbols('omega', real=True, positive=True)
R, λ = sym.symbols('R, lambda', complex=True)
t = sym.symbols('t', real=True, positive=True)
α = R/(sym.I*ω-λ)+sym.conjugate(R)/(sym.I*ω-sym.conjugate(λ))
sym.inverse_fourier_transform(α, ω, t)
How could I assume real part of lambda to be positive? If I assume lambda to have positive=True
, then sympy assumes imaginary=False
.
Any ideas?
Upvotes: 1
Views: 1008
Reputation:
Create two real symbols x, y, assume x positive, and let λ
be x + I*y
.
import sympy as sym
ω, x, t = sym.symbols('omega x t', positive=True)
y = sym.symbols('y', real=True)
R = sym.symbols('R')
λ = x + sym.I*y
α = R/(sym.I*ω-λ)+sym.conjugate(R)/(sym.I*ω-sym.conjugate(λ))
res = sym.inverse_fourier_transform(α, ω, t)
The result is
2*pi*R*exp(2*pi*t*(x + I*y)) + 2*pi*exp(2*pi*t*(x - I*y))*conjugate(R)
You can then return to single-symbol λ with substitution:
λ = sym.symbols('lambda')
res.subs(x + sym.I*y, λ).conjugate().subs(x + sym.I*y, λ).conjugate()
obtaining
2*pi*R*exp(2*pi*lambda*t) + 2*pi*exp(2*pi*t*conjugate(lambda))*conjugate(R)
(The trick with two conjugations is needed because subs
isn't going to replace x - I*y
with conjugate(lambda) otherwise.)
complex=True
is redundant; real numbers are included in complex numbers (7 is a complex number), so this has no effectreal=True
is redundant when positive=True
is givenUpvotes: 3