FD1D_HEAT_EXPLICIT Finite Difference Solution of the Time Dependent 1D Heat Equation using Explicit Time Stepping

FD1D_HEAT_EXPLICIT is a MATLAB library which solves the time-dependent 1D heat equation, using the finite difference method in space, and an explicit version of the method of lines to handle integration in time.

This program solves

```        dUdT - k * d2UdX2 = F(X,T)
```
over the interval [A,B] with boundary conditions
```        U(A,T) = UA(T),
U(B,T) = UB(T),
```
over the time interval [T0,T1] with initial conditions
```        U(X,T0) = U0(X)
```

A second order finite difference is used to approximate the second derivative in space.

The solver applies an explicit forward Euler approximation to the first derivative in time.

The resulting finite difference form can be written as

```       U(X,T+dt) - U(X,T)         ( U(X-dx,T) - 2 U(X,T) + U(X+dx,T) )
------------------  = k *  ------------------------------------ + F(X,T)
dt                          dx * dx
```
or, assuming we have solved for all values of U at time T, we have
```       U(X,T+dt) = U(X,T) + cfl * ( U(X-dx,T) - 2 U(X,T) + U(X+dx,T) ) + dt * F(X,T)
```
where "cfl" is the Courant-Friedrichs-Loewy coefficient:
```        cfl = k * dt / dx / dx
```
In order for accurate results to be computed by this explicit method, the cfl coefficient must be less than 0.5!

Other approaches would involve a fully implicit backward Euler approximation or the Crank-Nicholson approximation. These latter two methods have improved stability.

A second worthwhile change would be to replace the constant heat conductivity K by a function K(X,T). The spatial variation would allow for the modeling of a region divided into subregions of different materials.

Usage:

h_new = fd1d_heat_explicit ( x_num, x, t, dt, cfl, @rhs, @bc, h )
where
• x_num, the number of equally spaced nodes;
• x, the coordinates of the nodes;
• t, the current time;
• dt, the time step;
• cfl, the Courant-Friedrichs-Loewy coefficient;
• @rhs, a function to evaluate the right hand side source terms.
• @bc, a function to enforce the boundary conditions.
• h, the vector of temperatures at time T.
• h_new, the vector of temperatures at time T+DT.

Languages:

FD1D_HEAT_EXPLICIT is available in a C version and a C++ version and a FORTRAN77 version and a FORTRAN90 version and a MATLAB version and a Python version

Related Data and Programs:

FD1D_ADVECTION_FTCS, a MATLAB program which applies the finite difference method to solve the time-dependent advection equation ut = - c * ux in one spatial dimension, with a constant velocity, using the FTCS method, forward time difference, centered space difference.

FD1D_BURGERS_LAX, a MATLAB program which applies the finite difference method and the Lax-Wendroff method to solve the non-viscous time-dependent Burgers equation in one spatial dimension.

FD1D_BURGERS_LEAP, a MATLAB program which applies the finite difference method and the leapfrog approach to solve the non-viscous time-dependent Burgers equation in one spatial dimension.

FD1D_BVP, a MATLAB program which applies the finite difference method to a two point boundary value problem in one spatial dimension.

FD1D_HEAT_IMPLICIT, a MATLAB program which uses the finite difference method and implicit time stepping to solve the time dependent heat equation in 1D.

FD1D_HEAT_STEADY, a MATLAB program which uses the finite difference method to solve the steady (time independent) heat equation in 1D.

FD1D_PREDATOR_PREY, a MATLAB program which uses finite differences to solve a 1D predator prey problem.

FD1D_WAVE, a MATLAB program which applies the finite difference method to solve the time-dependent wave equation in one spatial dimension.

FEM1D, a MATLAB program which applies the finite element method, with piecewise linear basis functions, to a linear two point boundary value problem;

Reference:

1. George Lindfield, John Penny,
Numerical Methods Using MATLAB,
Second Edition,
Prentice Hall, 1999,
ISBN: 0-13-012641-1,
LC: QA297.P45.

Examples and Tests:

TEST01 runs with initial condition 50 everywhere, boundary conditions of 90 on the left and 70 on the right, and no right hand side source term.

TEST02 uses an exact solution of g(x,t) = exp ( - t ) .* sin ( sqrt ( k ) * x ).

TEST03 runs on the interval -5 <= X <= 5, with initial condition 15 on the entire left and 25 on the entire right. The solution should settle down to a straight line from the left boundary to the right.

You can go up one level to the MATLAB source codes.

Last revised on 31 January 2012.