My code:
restart;
a := 1/9;
b := 1/11;
c := 9/2;
w := sqrt(a*b);
n := 8*w;
alpha := a*b*c^(1/n);
omega := w;
sigma := 2*sqrt(a*b)/(a + b);
g := t -> piecewise(0 < t, a*sin(omega*t), t < 0, b*sin(alpha*t));
f := t -> a*sin(omega*t) + b*sin(alpha*t);
tau := k*`tau__*`;
`tau__*` := max(1/alpha, 1/omega);
# Compute the Fourier transforms
Fhat := fourier(f(t), t, xi);
Ghat := fourier(g(t), t, xi);
# Importing necessary package for animation and plotting
with(plots);
# Define function to plot |Fhat| and |Ghat| along with vertical lines at xi = omega and xi = alpha
PlotFunc := proc(k)
local FhatPlot, GhatPlot, VLines;
FhatPlot := plot(abs(subs(T=k*Ts, Fhat)), xi=0..max(alpha, omega)+1, color=red, legend="|Fhat(xi)|");
GhatPlot := plot(abs(subs(T=k*Ts, Ghat)), xi=0..max(alpha, omega)+1, color=blue, legend="|Ghat(xi)|");
VLines := plot([[omega, 0], [omega, 1], [alpha, 0], [alpha, 1]], color=[black, black, black, black], linestyle=[3,3,3,3]);
display([FhatPlot, GhatPlot, VLines], axes=boxed, legend=true);
end proc;
# Animate the PlotFunc
animation := animate(PlotFunc, [k], k=1..20, frames=20);
# Display the animation
display(animation);
At animation line, it get's stuck Evaluating forever. What is the problem and how can I solve it?
I tried to use k = 1 in hopes to simplify the evaluation but it still got stuck at Evaluating.
You have a few mistakes.
The fourier
command is part of the inttrans
package. You neither loaded that package not called that command using its fully qualified name. So Fhat
and Ghat
are assigned only unevaluated calls to the global name fourier
.
Also (if you were actually to use fourier
from the inttrans
package) the resulting expressions assigned to Fhat
and Ghat
depend only on xi
and not on T
. So after substituting k*Ts
for T
in those two expressions the results do not depend on k
, and so every frame of the animation is the same.
You don't need to invoke plots:-display
in order to merely show a constructed animation. (In fact, if you accidentally do then add the insequence=true
option or else you'll see the frames all together, side-by-side.)
I'll leave it to you to figure out muddles with T
and Ts
, so that you can construct frames which vary with k
. (Was either T
or Ts
intended to relate to tau
?)
restart;
a,b,c := 1/9, 1/11, 9/2:
w := sqrt(a*b): n := 8*w: alpha := a*b*c^(1/n): omega := w:
sigma := 2*sqrt(a*b)/(a + b):
g := t -> piecewise(0 < t, a*sin(omega*t), t < 0, b*sin(alpha*t)):
f := t -> a*sin(omega*t) + b*sin(alpha*t):
tau := k*`tau__*`: `tau__*` := max(1/alpha, 1/omega):
Fhat := inttrans:-fourier(f(t), t, xi):
Ghat := inttrans:-fourier(g(t), t, xi):
indets([Fhat,Ghat],And(name,Not(constant)));
PlotFunc := proc(k)
local FhatPlot, GhatPlot, VLines;
FhatPlot := plot(abs(subs(T=k*Ts, Fhat)), xi=0..max(alpha, omega)+1,
color=red, legend="|Fhat(xi)|"):
GhatPlot := plot(abs(subs(T=k*Ts, Ghat)), xi=0..max(alpha, omega)+1,
color=blue, legend="|Ghat(xi)|"):
VLines := plot([[omega, 0], [omega, 1], [alpha, 0], [alpha, 1]],
color=[black, black, black, black], linestyle=[3,3,3,3]);
plots:-display([FhatPlot, GhatPlot, VLines], axes=boxed);
end proc:
animation := plots:-animate(PlotFunc, [k], k=1..20, frames=20):
Now you need only this, to see what was assigned.
animation;
This also shows it, but is unnecessarily verbose here.
plots:-display(animation,insequence=true);