FEM1D - A 1D Finite Element Solver

FEM1D applies the finite element method to the one dimensional boundary value problem

-U''= F
on the interval
0 < X < 1.
The boundary conditions are
U(0) = U(1) = 0.
The code uses piecewise linear basis functions. The code assumes that an exact solution is known. The user supplies the right hand side of the boundary value problem in RHSFUN, and the formula for the exact solution in EXACT.

The code is broken up into a number of functions, some of which can be call directly or used for other purposes. In particular, BF_LINEAR and FE_LINEAR can easily be called directly to produce data suitable for plotting a basis function or a finite element function:

xc = linspace ( 0.0, 1.0, 11 );
x = linspace ( 0.0, 1.0, 100 );
[ b, dbdx ] = bf_linear ( 7, x, xc );
plot ( x, b )

FEM1D is a teaching code, and therefore is not optimized. For example, the stiffness matrix is stored as a full N by N matrix, and no effort is made to use a special solver for the resulting linear system. The loops of the assembly routine behave as though every basis function interacts with all others. The stiffness matrix is assembled with a one-point quadrature rule. There are many cases where a FOR loop is used but where a vectorized loop would be much faster. The boundary conditions, the basis functions, the exact solution, the differential equation are all quite simple. However, if the student can understand this program, it can easily be modified to be more efficient and flexible.

FEM1D was supplied by Professor Janet Peterson.

Files you may copy include:

Return to the MATLAB software page.


Last revised on 18 June 2001.