Worksheet: wave.mw 

Fourier Sine Series  

Solution to the Wave Equation 

 

This worksheet examines the sine series that arises in a separation of variables  

solution for the wave equation : 

 

u[tt]=`*`(`^`(c, 2))u[xx]     0 < x < L     u(0,t)=u(L,t)=0 

with initial condition 

u(x,0)=F(x)=L/2-abs(x-L/2)       0 < x< L 

u[t](x,0)=G(x)=0                            0 < x< L 

> restart:with(plots):
 

> L:=1;c:=1;
 

 

1
1 (1)
 

Least Squares Approximation of The Initial Condition 

Let's approximate the initial condition F(x) with the sum of sines that came from separation of variables. 

> F:=x->L/2-abs(x-L/2);
 

proc (x) options operator, arrow; `+`(`*`(`/`(1, 2), `*`(L)), `-`(abs(`+`(x, `-`(`*`(`/`(1, 2), `*`(L))))))) end proc (1.1)
 

> plot(F(x), x=0..L);
 

Plot_2d
 

> f:=n-> sin (n*Pi*x/L);
 

proc (n) options operator, arrow; sin(`/`(`*`(n, `*`(Pi, `*`(x))), `*`(L))) end proc (1.2)
 

> a:=n->(2/L)*int(F(x)*f(n),x=0..L);
 

proc (n) options operator, arrow; `+`(`/`(`*`(2, `*`(int(`*`(F(x), `*`(f(n))), x = 0 .. L))), `*`(L))) end proc (1.3)
 

> seq(a[n]=a(n),n=1..10);
 

a[1] = `+`(`/`(`*`(4), `*`(`^`(Pi, 2)))), a[2] = 0, a[3] = `+`(`-`(`/`(`*`(`/`(4, 9)), `*`(`^`(Pi, 2))))), a[4] = 0, a[5] = `+`(`/`(`*`(`/`(4, 25)), `*`(`^`(Pi, 2)))), a[6] = 0, a[7] = `+`(`-`(`/`(`*`... (1.4)
 

> g:= M->sum(a(m)*f(m),m=1..M);
 

proc (M) options operator, arrow; sum(`*`(a(m), `*`(f(m))), m = 1 .. M) end proc (1.5)
 

> h:=g(3);
 

`+`(`/`(`*`(4, `*`(sin(`*`(Pi, `*`(x))))), `*`(`^`(Pi, 2))), `-`(`/`(`*`(`/`(4, 9), `*`(sin(`+`(`*`(3, `*`(Pi, `*`(x))))))), `*`(`^`(Pi, 2))))) (1.6)
 

> plot({F(x),h},x=0..L);
 

Plot_2d
 

> s:=seq(g(2*M-1),M=1..6);
 

`+`(`/`(`*`(4, `*`(sin(`*`(Pi, `*`(x))))), `*`(`^`(Pi, 2)))), `+`(`/`(`*`(4, `*`(sin(`*`(Pi, `*`(x))))), `*`(`^`(Pi, 2))), `-`(`/`(`*`(`/`(4, 9), `*`(sin(`+`(`*`(3, `*`(Pi, `*`(x))))))), `*`(`^`(Pi, 2...
`+`(`/`(`*`(4, `*`(sin(`*`(Pi, `*`(x))))), `*`(`^`(Pi, 2)))), `+`(`/`(`*`(4, `*`(sin(`*`(Pi, `*`(x))))), `*`(`^`(Pi, 2))), `-`(`/`(`*`(`/`(4, 9), `*`(sin(`+`(`*`(3, `*`(Pi, `*`(x))))))), `*`(`^`(Pi, 2...
`+`(`/`(`*`(4, `*`(sin(`*`(Pi, `*`(x))))), `*`(`^`(Pi, 2)))), `+`(`/`(`*`(4, `*`(sin(`*`(Pi, `*`(x))))), `*`(`^`(Pi, 2))), `-`(`/`(`*`(`/`(4, 9), `*`(sin(`+`(`*`(3, `*`(Pi, `*`(x))))))), `*`(`^`(Pi, 2...
`+`(`/`(`*`(4, `*`(sin(`*`(Pi, `*`(x))))), `*`(`^`(Pi, 2)))), `+`(`/`(`*`(4, `*`(sin(`*`(Pi, `*`(x))))), `*`(`^`(Pi, 2))), `-`(`/`(`*`(`/`(4, 9), `*`(sin(`+`(`*`(3, `*`(Pi, `*`(x))))))), `*`(`^`(Pi, 2...
(1.7)
 

> plot({s,F(x)},x=0..L);
 

Plot_2d
 

Wave Equation Solution via Fourier Sine Series 

We can now reconstitute our solution to the heat equation, with the initial condition we derived. 

> u:=M->sum(a(m)*sin(m*Pi*x/L)*cos(c*m*Pi*t/L),m=1..M);
 

proc (M) options operator, arrow; sum(`*`(a(m), `*`(sin(`/`(`*`(m, `*`(Pi, `*`(x))), `*`(L))), `*`(cos(`/`(`*`(c, `*`(m, `*`(Pi, `*`(t)))), `*`(L)))))), m = 1 .. M) end proc (2.1)
 

> up:=u(10);
 

`+`(`/`(`*`(4, `*`(sin(`*`(Pi, `*`(x))), `*`(cos(`*`(Pi, `*`(t)))))), `*`(`^`(Pi, 2))), `-`(`/`(`*`(`/`(4, 9), `*`(sin(`+`(`*`(3, `*`(Pi, `*`(x))))), `*`(cos(`+`(`*`(3, `*`(Pi, `*`(t)))))))), `*`(`^`(...
`+`(`/`(`*`(4, `*`(sin(`*`(Pi, `*`(x))), `*`(cos(`*`(Pi, `*`(t)))))), `*`(`^`(Pi, 2))), `-`(`/`(`*`(`/`(4, 9), `*`(sin(`+`(`*`(3, `*`(Pi, `*`(x))))), `*`(cos(`+`(`*`(3, `*`(Pi, `*`(t)))))))), `*`(`^`(...
(2.2)
 

> plot3d(up,x=0..L,t=0..2.0,style=patchcontour,shading=zhue,axes=boxed);
 

Plot_2d
 

> animate(up,x=0..L,t=0..2*L,frames=51);
 

Plot_2d
 

>