# Animate doesn't work

I'm trying to animate plot:
a, A, B and C are constants. So I wrote the following script:

a:=1;
E1:=1.6*10^(-19);
E2:=1.6*10^(-19);
E3:=1.6*10^(-19);
h = 6.63*10^-34;
f[x_,t_] = (Sqrt[a]/2) (((10/16) Sin[Pi (x/a)])/E^(I (E1 (t/h)))
- ((5/16) Sin[3 Pi (x/a)])/E^(I (E2 (t/h)))
+ ((1/16) Sin[5 Pi (x/a)])/E^(I (E3 (t/h))));
Animate[Plot[f[x,t],{x,0,a}, Filling ->Bottom, AxesLabel ->Automatic],
{t,0,100, 1},AnimationRunning->False]


I get empty graph. Okay, maybe my function is not right, so I've tried f[x_,t_] = Sin(x*t); And again, the graph is empty. What am I doing wrong?

• Don’t use _ in the animate – Carl Woll Dec 21 '17 at 18:03
• you need to define h and also as @CarlWoll pointed, use f[x,t] inside Plot. Also make sure f[x,t] returns real value. – Sumit Dec 21 '17 at 18:08
• @Sumit h isn't defined as Planck constant? – Russiancold Dec 21 '17 at 18:10
• @Russiancold you should define the Planck constant as hbar = UnitConvert@Quantity[None, "PlanckConstant"] if you want to use its numerical value. – José Antonio Díaz Navas Dec 21 '17 at 18:18
• h isn't defined as Planck constant? Mathematica does not know that h is supposed to be Planck constant. You can do ?h to find out. Also, if it were, Mathematica uses UpperCase for such things. – Nasser Dec 21 '17 at 18:18

Assuming that you are trying to see the superposition of three different wavefunctions here is your answer.

a = 1;
E1 = 1.6*10^(-19);
E2 = 2.6*10^(-19);
E3 = 3.6*10^(-19);
h =  6.63*10^-34;
f[x_, t_] := (Sqrt[a]/ 2) (((10/16) Sin[Pi (x/a)])/ E^(I (E1 (t/h)))
- ((5/16) Sin[3 Pi (x/a)])/ E^(I (E2 (t/h)))
+ ((1/16) Sin[5 Pi (x/a)])/E^(I (E3 (t/h))));

Animate[Plot[Abs[f[x, t]]^2, {x, 0, a}, Filling -> Bottom, PlotRange -> {0, 0.25},
AxesLabel -> Automatic], {t, 0, 100, 1}, AnimationRunning -> False]


To make sure f[x,t] returns real value I use Abs[] in the Plot. If E1=E2=E3 then you will not see any variation in time.

As José Antonio Díaz Navas pointed out, you can set the value of Planck's constant h by QuantityMagnitude@UnitConvert@Quantity[None, "PlanckConstant"] as well.

• Thanks, so comparing to my script you removed "_" and defined h to make it work, right? Why Abs[] but not Re[]? – Russiancold Dec 21 '17 at 18:27
• Your function f[x,t] is complex. It is up to you to choose the real part, $\Re$ Re[], and/or the imaginary part, $\Im$ Im[], or Abs[] – José Antonio Díaz Navas Dec 21 '17 at 18:32
• That's due to my quantum mechanical habit of using $|/Psi|^2$ :) – Sumit Dec 21 '17 at 18:35
• @Sumit it's just my misunderstanding of Abs, somehow I forgot what is absolute value of complex number. Of course I need Abs but not Real part here. – Russiancold Dec 21 '17 at 18:37
• @Sumit is there any way to make the animation smoother or it's caused by this certain function? I'm trying to change dt param, but animation is still rough. Btw it's psi-function) – Russiancold Dec 21 '17 at 19:04