0
$\begingroup$

I am trying to plot a function of time using Euler's formula for the temporal part. As we all know, exponentials with imaginary arguments are linked to Cos and Sin by Euler's formula. When plotting with Manipulate I only get a result at t=0, which makes sense because I guess Mathematica can compute it in 0 giving 1. While computing that exponential in other times, it probably doesn't plot anything because it doesn't know which part of Euler's formula I'm asking for. Is it not automatic for Mathematica to pick one between Sin and Cos? Not even if I tell Mathematica ExpToTrig[Exp[- I omega t]] [[1]] or [[2]] I get a result. So do I always have to state which part to take from the relationship given by Euler? And how? If we use Re[Exp[- I omega t]] it actually works. But why doesnt ExpToTrig?

 axisFlip = # /. {x_Line | x_GraphicsComplex :> 
  MapAt[#~Reverse~2 &, x, 1], 
 x : (PlotRange -> _) :> x~Reverse~2} &;
 h = 5*10^-6;
 f = 173*10^3;
 omega = 2*N[Pi, 5]*f;
 Lc = Lnum/h;
 B1 = 1.8751;
 Lnum = N[250*10^-6];
 c = (Cos[B1 ] + Cosh[B1 ])/(Sin[B1  ] + Sinh[B1  ]);
 W[x_] = Cos[B1*x*h] - Cosh[B1*x*h] - c*(Sin[B1*x*h] - Sinh[B1*x*h]);
 dW[x1_] = -c (B1*h Cos[B1 x1 h] - B1*h Cosh[B1 x1 h]) - 
 B1*h Sin[B1 x1 h] - B1*h Sinh[B1 x1 h];
 vxbeam[x_, z_] = - I omega (- z dW[x]);
 vzbeam[x_] = -I omega (W[x ]);
 Manipulate[
 Plot[{Exp[- I omega t] Abs[vzbeam[x]], 
 Exp[- I omega t] Im[vzbeam[x]]}, {z, -1/2, 1/2}, 
 PlotLabel -> "Beam uniform z-component of velocity",
 AxesLabel -> {"m/s", "z"}, 
 PlotRange -> {{-1/2, 1/2}, {-Abs[vzbeam[Lnum/h]], 
  Abs[vzbeam[Lnum/h]]}}, Frame -> True, AspectRatio -> 1/5] // 
 axisFlip, {x, 0, Lnum/h, Appearance -> "Labeled"}, {t, 0, 5/f, 
 Appearance -> "Labeled"}]
$\endgroup$
  • 1
    $\begingroup$ Trig doesn't mean real and so complex doesn't automatically make sense for plotting in Mathematica. You want a real part, take it. Was that the question? $\endgroup$ – Kuba May 10 '17 at 9:07
  • $\begingroup$ @Kuba yes, but I was wondering: why if I take the first part of ExpToTrig[Exp[- I omega t]] isn't that equivalent to Re? As an output of ExpToTrig[Exp[- I omega t]][[1]] I get in fact Cos[1.0870*10^6 t] but Plot doesn't work $\endgroup$ – Andrea G May 10 '17 at 10:04
  • $\begingroup$ You can't count on Part for mathematical formulas. Take a look at FullForm of an expression. It will extrac the first element from the top expression but that does not mean anything in math context. $\endgroup$ – Kuba May 10 '17 at 10:10
  • 1
    $\begingroup$ ExpToTrig essentially means: please eliminate all the Exp[ I theta ] in favor of Cos[theta] + I Sin[theta]. That is, it's a function which coaxes Mathematica to adjust its [re]presentation of a quantity, rather than to actually change the quantity. "Why" it isn't equivalent to Re is simply: it's not designed to accomplish that but to fill another niche. $\endgroup$ – evanb May 10 '17 at 11:06
  • 2
    $\begingroup$ Not sure if I am missing something, but Exp[-I omega t] Abs[vzbeam[x]] is a function of x and t but the Plot variable is given as {z, -1/2, 1/2}. How is this supposed to work ? $\endgroup$ – Lotus May 10 '17 at 11:07

Your Answer

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

Browse other questions tagged or ask your own question.