Worksheet: Neumann.mw 

Fourier Cosine Series Solution: 

Neumann Problem for the Heat Equation 

 

This worksheet examines the Fourier cosine series that arises in a separation of variables solution for the Neumann problem for the heat equation: 

 

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

with initial condition 

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

                           0       L/2 < x < L      

> restart:with(plots):
 

> L:=1;
 

1
 

Fourier Cosine Series for  the Initial Condition 

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

> F:=piecewise(x<L/2,1,x=L/2,1/2,L/2<x,0);
 

piecewise(`<`(x, `/`(1, 2)), 1, x = `/`(1, 2), `/`(1, 2), `<`(`/`(1, 2), x), 0)
 

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

Plot_2d
 

> f0:=1/2;
 

`/`(1, 2)
 

> c0:=(2/L)*int(F,x=0..L);
 

1
 

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

proc (n) options operator, arrow; cos(`/`(`*`(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] = `+`(`/`(`*`(2), `*`(Pi))), c[2] = 0, c[3] = `+`(`-`(`/`(`*`(`/`(2, 3)), `*`(Pi)))), c[4] = 0, c[5] = `+`(`/`(`*`(`/`(2, 5)), `*`(Pi))), c[6] = 0, c[7] = `+`(`-`(`/`(`*`(`/`(2, 7)), `*`(Pi)))), ...
 

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

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

> h:=g(3);
 

`+`(`/`(1, 2), `/`(`*`(2, `*`(cos(`*`(Pi, `*`(x))))), `*`(Pi)), `-`(`/`(`*`(`/`(2, 3), `*`(cos(`+`(`*`(3, `*`(Pi, `*`(x))))))), `*`(Pi))))
 

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

Plot_2d
 

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

`+`(`/`(1, 2), `/`(`*`(2, `*`(cos(`*`(Pi, `*`(x))))), `*`(Pi))), `+`(`/`(1, 2), `/`(`*`(2, `*`(cos(`*`(Pi, `*`(x))))), `*`(Pi)), `-`(`/`(`*`(`/`(2, 3), `*`(cos(`+`(`*`(3, `*`(Pi, `*`(x))))))), `*`(Pi)...
`+`(`/`(1, 2), `/`(`*`(2, `*`(cos(`*`(Pi, `*`(x))))), `*`(Pi))), `+`(`/`(1, 2), `/`(`*`(2, `*`(cos(`*`(Pi, `*`(x))))), `*`(Pi)), `-`(`/`(`*`(`/`(2, 3), `*`(cos(`+`(`*`(3, `*`(Pi, `*`(x))))))), `*`(Pi)...
`+`(`/`(1, 2), `/`(`*`(2, `*`(cos(`*`(Pi, `*`(x))))), `*`(Pi))), `+`(`/`(1, 2), `/`(`*`(2, `*`(cos(`*`(Pi, `*`(x))))), `*`(Pi)), `-`(`/`(`*`(`/`(2, 3), `*`(cos(`+`(`*`(3, `*`(Pi, `*`(x))))))), `*`(Pi)...
`+`(`/`(1, 2), `/`(`*`(2, `*`(cos(`*`(Pi, `*`(x))))), `*`(Pi))), `+`(`/`(1, 2), `/`(`*`(2, `*`(cos(`*`(Pi, `*`(x))))), `*`(Pi)), `-`(`/`(`*`(`/`(2, 3), `*`(cos(`+`(`*`(3, `*`(Pi, `*`(x))))))), `*`(Pi)...
`+`(`/`(1, 2), `/`(`*`(2, `*`(cos(`*`(Pi, `*`(x))))), `*`(Pi))), `+`(`/`(1, 2), `/`(`*`(2, `*`(cos(`*`(Pi, `*`(x))))), `*`(Pi)), `-`(`/`(`*`(`/`(2, 3), `*`(cos(`+`(`*`(3, `*`(Pi, `*`(x))))))), `*`(Pi)...
`+`(`/`(1, 2), `/`(`*`(2, `*`(cos(`*`(Pi, `*`(x))))), `*`(Pi))), `+`(`/`(1, 2), `/`(`*`(2, `*`(cos(`*`(Pi, `*`(x))))), `*`(Pi)), `-`(`/`(`*`(`/`(2, 3), `*`(cos(`+`(`*`(3, `*`(Pi, `*`(x))))))), `*`(Pi)...
`+`(`/`(1, 2), `/`(`*`(2, `*`(cos(`*`(Pi, `*`(x))))), `*`(Pi))), `+`(`/`(1, 2), `/`(`*`(2, `*`(cos(`*`(Pi, `*`(x))))), `*`(Pi)), `-`(`/`(`*`(`/`(2, 3), `*`(cos(`+`(`*`(3, `*`(Pi, `*`(x))))))), `*`(Pi)...
`+`(`/`(1, 2), `/`(`*`(2, `*`(cos(`*`(Pi, `*`(x))))), `*`(Pi))), `+`(`/`(1, 2), `/`(`*`(2, `*`(cos(`*`(Pi, `*`(x))))), `*`(Pi)), `-`(`/`(`*`(`/`(2, 3), `*`(cos(`+`(`*`(3, `*`(Pi, `*`(x))))))), `*`(Pi)...
`+`(`/`(1, 2), `/`(`*`(2, `*`(cos(`*`(Pi, `*`(x))))), `*`(Pi))), `+`(`/`(1, 2), `/`(`*`(2, `*`(cos(`*`(Pi, `*`(x))))), `*`(Pi)), `-`(`/`(`*`(`/`(2, 3), `*`(cos(`+`(`*`(3, `*`(Pi, `*`(x))))))), `*`(Pi)...
`+`(`/`(1, 2), `/`(`*`(2, `*`(cos(`*`(Pi, `*`(x))))), `*`(Pi))), `+`(`/`(1, 2), `/`(`*`(2, `*`(cos(`*`(Pi, `*`(x))))), `*`(Pi)), `-`(`/`(`*`(`/`(2, 3), `*`(cos(`+`(`*`(3, `*`(Pi, `*`(x))))))), `*`(Pi)...
 

> 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, 2)
.5000000000
 

> 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(%);
 

 

`+`(`/`(`*`(`/`(1, 4), `*`(`+`(`*`(`^`(Pi, 2)), 8))), `*`(`^`(Pi, 2)))), `+`(`/`(`*`(`/`(1, 4), `*`(`+`(`*`(`^`(Pi, 2)), 8))), `*`(`^`(Pi, 2)))), `+`(`/`(`*`(`/`(1, 36), `*`(`+`(`*`(9, `*`(`^`(Pi, 2))...
`+`(`/`(`*`(`/`(1, 4), `*`(`+`(`*`(`^`(Pi, 2)), 8))), `*`(`^`(Pi, 2)))), `+`(`/`(`*`(`/`(1, 4), `*`(`+`(`*`(`^`(Pi, 2)), 8))), `*`(`^`(Pi, 2)))), `+`(`/`(`*`(`/`(1, 36), `*`(`+`(`*`(9, `*`(`^`(Pi, 2))...
.4526423670, .4526423670, .4751581859, .4751581859, .4832638805, .4832638805, .4873994390, .4873994390, .4899011965
.4526423670, .4526423670, .4751581859, .4751581859, .4832638805, .4832638805, .4873994390, .4873994390, .4899011965
 

Heat Equation Revisited 

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

> u:=M->c0*f0+ sum(c(m)*f(m)*exp(-(m*Pi/L)^2*t),m=1..M);
 

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

> u15:=u(15);
 

`+`(`/`(1, 2), `/`(`*`(2, `*`(cos(`*`(Pi, `*`(x))), `*`(exp(`+`(`-`(`*`(`^`(Pi, 2), `*`(t)))))))), `*`(Pi)), `-`(`/`(`*`(`/`(2, 3), `*`(cos(`+`(`*`(3, `*`(Pi, `*`(x))))), `*`(exp(`+`(`-`(`*`(9, `*`(`^...
`+`(`/`(1, 2), `/`(`*`(2, `*`(cos(`*`(Pi, `*`(x))), `*`(exp(`+`(`-`(`*`(`^`(Pi, 2), `*`(t)))))))), `*`(Pi)), `-`(`/`(`*`(`/`(2, 3), `*`(cos(`+`(`*`(3, `*`(Pi, `*`(x))))), `*`(exp(`+`(`-`(`*`(9, `*`(`^...
`+`(`/`(1, 2), `/`(`*`(2, `*`(cos(`*`(Pi, `*`(x))), `*`(exp(`+`(`-`(`*`(`^`(Pi, 2), `*`(t)))))))), `*`(Pi)), `-`(`/`(`*`(`/`(2, 3), `*`(cos(`+`(`*`(3, `*`(Pi, `*`(x))))), `*`(exp(`+`(`-`(`*`(9, `*`(`^...
 

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

Plot_2d
 

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

Plot_2d
 

>