Basic Matlab example of solving the 1 dimensional poisson equation with FEM (=Finite element method)

License: CC0-1.0

Language: MATLAB


Basic Matlab example of solving the 1 dimensional poisson equation with FEM (=Finite element method)


Tutorial to get a basic understanding about implementing FEM using MATLAB. In this example we want to solve the poisson equation with homogeneous boundary values.

Get sources

 git clone

Run FEM Method in Matlab

Just go inside the project root directory and run the main.m script by enter


in Matlab Command Window.

Change User input

You can change some values as the Interval, the step size of the FEM and modify the RHS of the equation.

To modify the Interval or the step size just go in the top of main.m script to change the values x1, x2 to change the left or right boundary of the interval. To change the step size just modify the value for h. Here is an short example of an possible setup:

 x1 = -2;
 x2 = 2;
 h = 1./16;

Another possibility to play around with this FEM method is to change the RHS of the equation. The RHS is defined in the f.m script. If you open it you can return some other function. Just take attention that the function has to work for arrays. So use operations like .* instead of *. Here is an short example:

 y = x.^3;

Mathematical Context

To understand whats going on in this Matlab example we need do do some math. Here you get a short mathematical introduction how to prepare the poission equation for FEM.

Mathematical Problem

We want to solve following mathematical problem - 1 dimensional poisson equation with homogeneous dirichlet boundary condition:

Poisson Equation

Poisson Equation Boundary

Before we start the implementation we need to do some math ;). We need to derive a weak formulation of the Equations above. So lets start ...

Weak formulation

In each case if you want to do FEM you have to derive the weak formulation. We choose our shape functions out of the Sobolev Space Test function. Multiplying the shape function to the Poisson equation above and integrating over the interval lead us to Start Weak Form After integration by parts we get Finish Weak Form In the previous equation we used that the boundary integral is zero because of the choice of the shape function.

To summarize our result we get the weak form of the poisson equation with dirichlet boundary condition:

Find solution that

Weak Form

for all Test function.

Discretization and FEM

Project Statistics

Sourcerank 3
Repository Size 28.3 KB
Stars 0
Forks 0
Watchers 1
Open issues 0
Dependencies 0
Contributors 1
Tags 0
Last updated
Last pushed

Top Contributors See all


Something wrong with this page? Make a suggestion

Login to resync this repository