| Author |
Comment/Response |
Jason
|
02/27/10 02:55am
Somehow when i'm compiling a procedure line by line it works out just fine but when i compile the procedure to work on the inputs automatically it doesn't work. can anyone point out what's wrong please ? - this procedure is set to manually work out the fourier series and plot it -
So: Line by line;
Clear[init, final, a, b, n, x, f, s]
f[x_] := Piecewise[{{-1, -Pi < x <= 0}, {1, 0 < x <= Pi}}]
s := Infinity
final := Pi
init := -Pi
interval := {init, final}
L := (interval[[2]] - interval[[1]])/2
a[n_] := 2/L Integrate[
f[x] Cos[(n Pi x)/L], {x, interval[[1]], interval[[2]]}]
b[n_] := 2/L Integrate[
f[x] Sin[(n Pi x)/L], {x, interval[[1]], interval[[2]]}]
FourierFunction :=
a[0]/2 + Sum[a[n] Cos[(n Pi x)/L] + b[n] Sin[(n Pi x)/L], {n, 1, s}]
Plot[FourierFunction, {x, init, final}]
Now for the procedure the pre-requisite is that the user inputs the function ... so :
Clear[init, final, a, b, n, x, f, s]
f[x_] := Piecewise[{{-1, -Pi < x <= 0}, {1, 0 < x <= Pi}}]
ProgFourier[init_,final_,s_]:=
(
interval := {init, final};
L := (interval[[2]] - interval[[1]])/2;
a[n_] := 2/L Integrate[
f[x] Cos[(n Pi x)/L], {x, interval[[1]], interval[[2]]}];
b[n_] := 2/L Integrate[
f[x] Sin[(n Pi x)/L], {x, interval[[1]], interval[[2]]}];
FourierFunction :=
a[0]/2 + Sum[a[n] Cos[(n Pi x)/L] + b[n] Sin[(n Pi x)/L], {n, 1, s}];
Plot[FourierFunction, {x, init, final}]
)
Thanks for any help
URL: , |
|