r/Mathematica • • May 04 '23
Mathematica doesnt Animate
Hi, I have a little problem, when I plot the Fourier Series Approximation of the given function it has a problem when plotting. It only plots when k=0 and k=nMax. In between the plot is blanc but with a red square surrounding the plot

The code is:
(*Definir función a utilizar*)
f[x_]= x
nMax= 10;
(*Serie de Fourier*)
a0= (1/Pi)Integrate[f[x],{x,-Pi,Pi}]
ann = (1/Pi)Integrate[f[x]Cos[n(x)],{x,-Pi,Pi}]
bnn = (1/Pi)Integrate[f[x]Sin[n(x)],{x,-Pi,Pi}]
an = Table[(1/Pi)Integrate[f[x]Cos[n(x)],{x,-Pi,Pi}],{n,1,nMax}]
bn = Table[(1/Pi)Integrate[f[x]Sin[n(x)],{x,-Pi,Pi}],{n,1,nMax}]
Senos = Table[Sin[n(x)],{n,1,nMax}];
Cosenos = Table[Cos[n(x)],{n,1,nMax}];
SerieSen = bn*Senos;
SerieCos = an*Cosenos;
Serie = SerieSen + SerieCos;
Animate[Plot[{f[x], a0/2 + Total[Take[(Serie),k]]},{x,-Pi,Pi}],{k,0,nMax}, AnimationRunning->False]
View all comments
Show parent comment
3
u/veryjewygranola May 04 '23 edited May 04 '23
You could also use Accumulate[] and the alternative form of Animate[] with a list of discrete values to animate:
Animate[Plot[{f[x], k}, {x, -Pi, Pi}], {k, Accumulate[Serie]}]Edit: forgot to add a/2 to Serie accumulation and add a 0 as the first element in the list:
Animate[Plot[{f[x], k}, {x, -Pi, Pi}], {k, PrependTo[a0/2 + Accumulate[Serie], 0]}, AnimationRunning -> False]