I have a complex expression with real positive variables only.
Mathematica Input Style:
PP = -((α (γ Cosh[y1 α] + α Sinh[y1 α])(-γ Cosh[(-L + y2) α] + α Sinh[(-L + y2) α]))
/(s (2 α γ Cosh[L α] + (α^2 + γ^2) Sinh[L α]))) /. α -> Sqrt[s/d] /.
γ -> (kd + s)/ka /. s -> -ω*I
which leads to
$ PP=-\frac{i \sqrt{-\frac{i \omega }{d}} \left(\frac{(\text{kd}-i \omega ) \text{Cosh}\left[\text{y1} \sqrt{-\frac{i \omega }{d}}\right]}{\text{ka}}+\sqrt{-\frac{i \omega }{d}} \text{Sinh}\left[\text{y1} \sqrt{-\frac{i \omega }{d}}\right]\right) \left(-\frac{(\text{kd}-i \omega ) \text{Cosh}\left[(-L+\text{y2}) \sqrt{-\frac{i \omega }{d}}\right]}{\text{ka}}+\sqrt{-\frac{i \omega }{d}} \text{Sinh}\left[(-L+\text{y2}) \sqrt{-\frac{i \omega }{d}}\right]\right)}{\omega \left(\frac{2 (\text{kd}-i \omega ) \sqrt{-\frac{i \omega }{d}} \text{Cosh}\left[L \sqrt{-\frac{i \omega }{d}}\right]}{\text{ka}}+\left(\frac{(\text{kd}-i \omega )^2}{\text{ka}^2}-\frac{i \omega }{d}\right) \text{Sinh}\left[L \sqrt{-\frac{i \omega }{d}}\right]\right)} $
Now I want to extract the real part of this by assuming real only variables and then
Re[PP]
. Mathematica 8 can't extract it.
I saw on different forums that many people have had difficulties with extracting real or imaginary parts of expressions with built-in Re
.
Some propose to replace Re
by ComplexExpand[ ( PP + Conjugate[PP] )/2 ]
, which seems to work well in some cases. Do you have other suggestions?
All the variables are real and positive, so that I define at the beginning of my Mathematica notebook:
$Assumptions = ω > 0 && d > 0 && L > 0 && y1 > 0 && y2 > 0 &&
y1 < y2 && ka > 0 && kd > 0 && s > 0 && y1 < L && y2 < L
My version of Mathematica is $Version = "8.0 for Linux x86 (64-bit) (October 10, 2011)"
ComplexExpand
does not work well ? $\endgroup$ComplexExpand[Re[PP]]
does return a result. The output is ugly because the result also depends on the sign of variables. $\endgroup$