I am trying to plot a function in which is piecewise defined. I found the Fourier coefficients of this, and my question is how to define even
& odd
conditions for the Piecewise
command? I used 2n and 2n+1 for even & odd respectively, but this does not suffice. I have a MWE
below.
Clear[f,a,b,F]
f[t_]=Piecewise[{{-Sqrt[9+t+t^2],-2<t<0},{Exp[Sin[t]],0<=t<=2}}]
a0=23/9;
a[k_]=Piecewise[{{20/(k^4Pi^4),2k},{-83/(k Pi),2k+1}}]
b[k_]=Piecewise[{{-92/(k^3 Pi^3),2k},{-53/(k Pi)+14/(k^2 Pi^2),2k+1}}]
F[t_]=a0/2+Sum[a[k]Cos[(k Pi t)/2]+b[k]Sin[(k Pi t)/2],{k,1,20}];
Plot[{f[t],F[t]},{t,-1,1}]
OddQ[n]
andEvenQ[n]
to test values ofn
. $\endgroup$Clear
but it was not clearing my variables, so when I usedRemove
that had done the trick. Along with a pair of parentheses I was missing:)
. $\endgroup$