你看看FourierSinSeries之类的函数的帮助——虽然很想这么说,但是,楼主这个问题其实挺有讨论价值的。这其实牵扯到一个我早想开帖讨论却一直拖着没动的问题:
Mathematica的FourierSeries及几个相关函数用起来不够方便。
这种不方便体现在两点:
1. FourierSeries只给出一个
并非通项形式的有限和——这种形式的结果适合直接用于数值计算,但是,很多时候我们是需要获取级数通项的——比如与某些材料的结果进行对比的时候。实际上Mathematica并非求不了级数通项(具体参看FourierCoefficient等函数的帮助),但是软件就是没给我们提供直接输出通项形式的级数的选项。
2. FourierSeries等函数默认只在“标准”的那个定义区间上进行展开。软件没有为我们提供一个简洁的方法进行区间的重设。
所以,让我们来给傅立叶级数写个壳来克服一下:
easyFourierSinCoefficient[expr_, {t_, a_, b_}, k_] :=
FourierSinCoefficient[expr /. t -> trans[{a, b}, {0, Pi}, t], t, k] /.
t -> trans[{0, Pi}, {a, b}, t]
Block[{t, a, b, k},
easySinTerm[{t_, a_, b_}, k_] =
Sin[k t] /. t -> First@RescalingTransform[{{a, b}}, {{0, Pi}}][{t}] // Simplify];
easyFourierSinSeries[expr_, {t_, a_, b_}, n_: C] :=
HoldForm@Sum[#, #2] &[
easyFourierSinCoefficient[
expr, {t, a, b}, \[FormalK]] easySinTerm[{t, a, b}, \[FormalK]], {\[FormalK], n}]
easyFourierCoefficient[expr_, {t_, a_, b_}, k_] :=
FourierCoefficient[expr /. t -> trans[{a, b}, {-Pi, Pi}, t], t, k] /.
t -> trans[{-Pi, Pi}, {a, b}, t]
Block[{t, a, b, k},
easyTerm[{t_, a_, b_}, k_] =
Exp[I k t] /. t -> First@RescalingTransform[{{a, b}}, {{-Pi, Pi}}][{t}] // Simplify];
easyFourierSeries[expr_, {t_, a_, b_}, n_: C] :=
HoldForm@Sum[#, #2] &[
Piecewise[{{easyFourierCoefficient[expr, {t, a, b}, \[FormalK]], \[FormalK] != 0}},
easyFourierCoefficient[expr, {t, a, b}, 0]] easyTerm[{t, a,
b}, \[FormalK]], {\[FormalK], -n, n}]
easyFourierCosCoefficient[expr_, {t_, a_, b_}, k_] :=
FourierCosCoefficient[expr /. t -> trans[{a, b}, {0, Pi}, t], t, k] /.
t -> trans[{0, Pi}, {a, b}, t]
Block[{t, a, b, k},
easyCosTerm[{t_, a_, b_}, k_] =
Cos[k t] /. t -> First@RescalingTransform[{{a, b}}, {{0, Pi}}][{t}] // Simplify];
easyFourierCosSeries[expr_, {t_, a_, b_}, n_: C] :=
easyFourierCosCoefficient[expr, {t, a, b}, 0]/2 + HoldForm@Sum[#, #2] &[
easyFourierCosCoefficient[
expr, {t, a, b}, \[FormalK]] easyCosTerm[{t, a, b}, \[FormalK]], {\[FormalK], n}]
如果你在版本10以上,那可以用Activate系的函数来代替HoldForm。
下面我们来试用一下:
expr
@1 = 1 - x^2;
series@1 =
easyFourierCosSeries[expr@1, {x, -1/2, 1/2}]


Plot[{expr@1, series@1 /. C -> 12 // ReleaseHold} // Flatten // Evaluate, {x, -1/2, 1/2},
PlotRange -> All]


expr
@2 = Piecewise[{{x, -1 <= x < 0}, {1, 0 <= x < 1/2}, {-1, 1/2 <= x < 1}}]
series@2 =
easyFourierSeries[expr@2, {x, -1, 1}]


Plot[{expr@2, series@2 /. C -> 12 // ReleaseHold} // Flatten // Evaluate, {x, -1, 1},
PlotRange -> All]


expr@3 = Piecewise[{{2 x + 1, -3 <= x < 0}, {1, 0 <= x < 3}}]
series@3 =
easyFourierSinSeries[expr@3, {x, -1, 1}]


Plot[{expr@3, series@3 /. C -> 12 // ReleaseHold} // Flatten // Evaluate, {x, -1, 1},
PlotRange -> All]
