It's time for a more involved example that illustrates the use of for
loops and lists in numerical computing. The analytical solution to a partial differential equation often includes a summation of an infinite series. In this example, we are going to write a short program that computes a solution to the diffusion equation in one dimension on a finite interval of length l. The diffusion equation is defined by:
The diffusion equation can be used to model physical problems such as the diffusion of heat in a solid, or the diffusion of molecules through a gas or liquid. The value of v(x,t) can represent the temperature or concentration at a point x and time t. The value of v is fixed at each end of the interval:
The initial condition is that v is equal to an arbitrary function f(x):
The solution to this boundary value problem can be found in a textbook such as The Conduction of Heat in Solids by H. S. Carslaw and J. C. Jaeger:
This...