fd1d_heat_explicit, an Octave code which solves the time-dependent 1D heat equation, using the finite difference method (FDM) 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 * dxor, 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 / dxIn 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.
h_new = fd1d_heat_explicit ( x_num, x, t, dt, cfl, @rhs, @bc, h )where
The computer code and data files described and made available on this web page are distributed under the MIT license
fd1d_heat_explicit is available in a C version and a C++ version and a Fortran90 version and a MATLAB version and an Octave version and a Python version
fd1d_advection_ftcs, an Octave code 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, an Octave code 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, an Octave code 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, an Octave code which applies the finite difference method to a two point boundary value problem in one spatial dimension.
fd1d_heat_implicit, an Octave code which uses the finite difference method and implicit time stepping to solve the time dependent heat equation in 1d.
fd1d_heat_steady, an Octave code which uses the finite difference method to solve the steady (time independent) heat equation in 1d.
fd1d_predator_prey, an Octave code which uses finite differences to solve a 1d predator prey problem.
fd1d_wave, an Octave code which applies the finite difference method to solve the time-dependent wave equation in one spatial dimension.
fem1d, an Octave code which applies the finite element method, with piecewise linear basis functions, to a linear two point boundary value problem;