Worksheet: heatsine.mw 

Fourier Sine Series  

and a solution to the Heat Equation 

 

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

solution for the heat equation : 

 

u[t]=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 

> restart:with(plots):
 

> L:=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:=L/2-abs(x-L/2);
 

`+`(`/`(1, 2), `-`(abs(`+`(x, `-`(`/`(1, 2))))))
 

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

Plot_2d
 

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

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

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

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

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

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

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

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

> h:=g(3);
 

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

> plot({F,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...
 

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

Plot_2d
 

Bessel's Inequality and Parseval's Theorem 

Let's compute the (norm)^2 of F(x) and the n-term approximation of F 

> normF:=int(F^2,x=0..L); evalf(%);
 

 

`/`(1, 12)
0.8333333333e-1
 

> normg:=N-> int(g(N)^2,x=0..L);
 

proc (N) options operator, arrow; int(`*`(`^`(g(N), 2)), x = 0 .. L) end proc
 

> seq(normg(n),n=1..9); evalf(%);
 

 

`+`(`/`(`*`(8), `*`(`^`(Pi, 4)))), `+`(`/`(`*`(8), `*`(`^`(Pi, 4)))), `+`(`/`(`*`(`/`(656, 81)), `*`(`^`(Pi, 4)))), `+`(`/`(`*`(`/`(656, 81)), `*`(`^`(Pi, 4)))), `+`(`/`(`*`(`/`(410648, 50625)), `*`(`...
0.8212785800e-1, 0.8212785800e-1, 0.8314178217e-1, 0.8314178217e-1, 0.8327318674e-1, 0.8327318674e-1, 0.8330739243e-1, 0.8330739243e-1, 0.8331991001e-1
0.8212785800e-1, 0.8212785800e-1, 0.8314178217e-1, 0.8314178217e-1, 0.8327318674e-1, 0.8327318674e-1, 0.8330739243e-1, 0.8330739243e-1, 0.8331991001e-1
 

Heat Equation Revisited 

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

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

proc (M) options operator, arrow; sum(`*`(c(m), `*`(sin(`/`(`*`(m, `*`(Pi, `*`(x))), `*`(L))), `*`(exp(`+`(`-`(`/`(`*`(`^`(m, 2), `*`(`^`(Pi, 2), `*`(t))), `*`(`^`(L, 2))))))))), m = 1 .. M) end proc
 

> u6:=u(6);
 

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

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

Plot_2d
 

> animate(u6,x=0..L,t=0..0.5,frames=50);
 

Plot_2d
 

>