1
$\begingroup$

I have a code:

θk = 0.1; kz = 2 π Sin[θk];

(*Cylindrical*)
A[mγ_, Λ_, x_, y_, z_, ϕ_, k_, ω_,t_] = Exp[-I (ω t - k Cos[θk] z + ϕ)] Sqrt[k Sin[θk]/(2 π)] ((Λ/Sqrt [2]) Exp[I mγ ArcTan[x, y]] Sin[θk] BesselJ[mγ, k Sin[θk] Sqrt[x^2 + y^2]] {0, 0, 1} +I^(-Λ) Exp[I (mγ - Λ) ArcTan[x, y]] Cos[θk/2]^2 BesselJ[mγ - Λ,k Sin[θk] Sqrt[x^2 + y^2]] {-Λ , -I, 0} +I^Λ Exp[I (mγ + Λ) ArcTan[x, y]] Sin[θk/2]^2 BesselJ[mγ + Λ,k Sin[θk] Sqrt[x^2 + y^2]] {Λ, -I, 0});

(*Cartesian*)
ACart[mγ_, Λ_, x_, y_, z_, ϕ_,k_, ω_,t_] = {A[mγ, Λ, x, y, z, ϕ, k, ω,t][[1]] Cos[ArcTan[x, y]] -A[mγ, Λ, x, y, z, ϕ, k, ω,t][[2]] Sin[ArcTan[x, y]],A[mγ, Λ, x, y, z, ϕ, k, ω,t][[1]] Sin[ArcTan[x, y]] +A[mγ, Λ, x, y, z, ϕ, k, ω,t][[2]] Cos[ArcTan[x, y]],A[mγ, Λ, x, y, z, ϕ, k, ω,t][[3]]};
Bc[mγ_, Λ_, x_, y_, z_, ϕ_, k_, ω_,t_] = {D[ACart[mγ, Λ, x, y, z, ϕ, k, ω,t][[3]], y] -D[ACart[mγ, Λ, x, y, z, ϕ, k, ω,t][[2]], z],D[ACart[mγ, Λ, x, y, z, ϕ, k, ω,t][[1]], z] -D[ACart[mγ, Λ, x, y, z, ϕ, k, ω,t][[3]], x],D[ACart[mγ, Λ, x, y, z, ϕ, k, ω,t][[2]], x] -D[ACart[mγ, Λ, x, y, z, ϕ, k, ω,t][[1]], y]};
Ec[mγ_, Λ_, x_, y_, z_, ϕ_, k_, ω_,t_] = -D[ACart[mγ, Λ, x, y, z, ϕ, k, ω,t], t];
l1 = 1; l2 = 2;
Elin[x_, y_, z_, Φ_, k1_, k2_, ω_, t_] = Ec[l1 + 1, 1, x, y, z, 0, k1, ω, t] - Ec[l1 - 1, -1, x, y, z, 0, k1, ω, t] + Ec[l2 + 1, 1, x, y, z, Φ, k2, ω, t] - Ec[l2 - 1, -1, x, y, z, Φ, k2, ω, t];
Blin[x_, y_, z_, Φ_, k1_, k2_, ω_, t_] = Bc[l1 + 1, 1, x, y, z, 0, k1, ω, t] -Bc[l1 - 1, -1, x, y, z, 0, k1, ω, t] + Bc[l2 + 1, 1, x, y, z, Φ, k2, ω, t] - Bc[l2 - 1, -1, x, y, z, Φ, k2, ω, t];
Simplify[ComplexExpand[Refine[Re[Elin[x, y, 0, 0, 2 π, 2 π, 2 π, 0]], {Element[x, Reals], Element[y, Reals]}]]]

I need it to take a proper Im and Re parts of Elin and Blin so that I could take partial derivatives afterwards, but it leaves stuff like Re[BesselJ] and Arg[x + i y] untreated no matter what I do. I have tried to put Refine in various places telling that x,y,z,k,$\phi$ etc. are all real, that $m_{\gamma}$ is integer... Nothing works. Any help is appreciated!

$\endgroup$
  • 2
    $\begingroup$ The documentation for Arg says: Arg[z] is left unevaluated if z is not a numeric quantity Since your x and y are not numeric I believe that explains why your Arg[x+I y] is not being further transformed. Can you state what you want Arg[x+I y] to be transformed into? Perhaps with that something can be done. $\endgroup$ – Bill Mar 25 at 16:58
  • $\begingroup$ @Bill By def ArcTan[x,y], so that it could take a symbolic derivative of x or y properly afterwards $\endgroup$ – MsTais Mar 25 at 17:01
  • 1
    $\begingroup$ Please look at Simplify[ComplexExpand[Elin[x,y,0,0,2 Pi,2 Pi,2 Pi,0] ]/.Arg[x+I y]->ArcTan[x,y],Element[x|y,Reals]] and suggest what the next step needs to be. $\endgroup$ – Bill Mar 25 at 17:11
  • $\begingroup$ @Bill It works as well, thanks! $\endgroup$ – MsTais Mar 25 at 17:21
  • $\begingroup$ Just in case you might be a little new at Mathematica, check the documentation for ArcTan which states ArcTan[x,y] gives the arctangent of y/x and that sometimes surprises new users. $\endgroup$ – Bill Mar 25 at 17:36
5
$\begingroup$

Use TargetFunctions option to ComplexExpand

θk = 1/10; (* use exact value for parameter *)

ElinRe[x_, y_] = Assuming[Element[{x, y}, Reals],
  Elin[x, y, 0, 0, 2 π, 2 π, 2 π, 0] // Re //
    ComplexExpand[#, TargetFunctions -> {Re, Im}] & //
   Simplify]

(* {π Sqrt[
  Sin[1/10]] ((1/(x^2 + y^2))
    BesselJ[1, 
      2 π Sqrt[x^2 + y^2] Sin[1/10]] (x^2 (-1 + Cos[1/10]) - 
       y^2 (1 + 3 Cos[1/10])) + (1/Sqrt[x^2 + y^2])
    2 (x BesselJ[0, 2 π Sqrt[x^2 + y^2] Sin[1/10]] Sin[1/20]^2 - 
       x BesselJ[4, 2 π Sqrt[x^2 + y^2] Sin[1/10]] Cos[
         4 ArcTan[x, y]] Sin[1/20]^2 - 
       2 y BesselJ[2, 2 π Sqrt[x^2 + y^2] Sin[1/10]] Cos[1/20]^2 Sin[
         2 ArcTan[x, y]] - 
       BesselJ[3, 2 π Sqrt[x^2 + y^2] Sin[1/10]] Sin[1/
         20]^2 (x Cos[3 ArcTan[x, y]] - y Sin[3 ArcTan[x, y]]) + 
       y BesselJ[4, 2 π Sqrt[x^2 + y^2] Sin[1/10]] Sin[1/20]^2 Sin[
         4 ArcTan[x, y]])), (1/((x^2 + y^2)^(3/2)))
 2 π Sqrt[
  Sin[1/10]] (2 x y Sqrt[x^2 + y^2]
      BesselJ[1, 2 π Sqrt[x^2 + y^2] Sin[1/10]] Cos[1/
      10] - (x^2 + 
       y^2) (-y BesselJ[0, 2 π Sqrt[x^2 + y^2] Sin[1/10]] Sin[1/20]^2 + 
       y BesselJ[4, 2 π Sqrt[x^2 + y^2] Sin[1/10]] Cos[
         4 ArcTan[x, y]] Sin[1/20]^2 - 
       2 x BesselJ[2, 2 π Sqrt[x^2 + y^2] Sin[1/10]] Cos[1/20]^2 Sin[
         2 ArcTan[x, y]] + 
       BesselJ[3, 2 π Sqrt[x^2 + y^2] Sin[1/10]] Sin[1/
         20]^2 (y Cos[3 ArcTan[x, y]] + x Sin[3 ArcTan[x, y]]) + 
       x BesselJ[4, 2 π Sqrt[x^2 + y^2] Sin[1/10]] Sin[1/20]^2 Sin[
         4 ArcTan[x, y]])), -(1/(x^2 + y^2))
  Sqrt[2] π Sin[1/10]^(
   3/2) (y Sqrt[x^2 + y^2] BesselJ[1, 2 π Sqrt[x^2 + y^2] Sin[1/10]] + 
     2 x y BesselJ[2, 
       2 π Sqrt[x^2 + y^2] Sin[1/10]] + (x^2 + y^2) BesselJ[3, 
       2 π Sqrt[x^2 + y^2] Sin[1/10]] Sin[3 ArcTan[x, y]])} *)

Plot3D[
 Evaluate@ElinRe[x, y], {x, -5, 5}, {y, -5, 5},
 AxesLabel -> Automatic, PlotLegends -> Automatic]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.