I am trying to find some resources to help explain how to choose boundary conditions when using finite difference methods to solve PDEs.
The books and notes which I currently have access to all say similar things:
The general rules governing stability in the presence of boundaries are far too complicated for an introductory text; they require sophisticated mathematical machinery
(A. Iserles A First Course in the Numerical Analysis of Differential Equations)
For example, when trying to implement the 2-step leapfrog method for the advection equation:
$u_i^{n+1} = u_i^{n-1} + \mu (u_{i+1}^n - u_{i-1}^n)$
using MATLAB
M = 100; N = 100;
mu = 0.5;
c = [mu 0 -mu];
f = @(x)(exp(-100*(x-0.5).^2));
u = zeros (M, N);
x = 1/(M+1) * (1:M);
u(:,1) = f(x);
u(:,2) = f(x + mu/(M+1));
for i = 3:N
hold off;
u(:,i) = conv(u(:,i-1),c,'same') + u(:,i-2);
plot(x, u(:,i));
axis( [ 0 1 0 2] )
drawnow;
end
The solution behaves nicely until it reaches the boundary, when it very suddenly starts behaving badly.
Where can I learn how to handle boundary conditions like this?