Using the MATLAB PDE TOOLBOX
The MATLAB PDE Toolbox is a tool for solving two-dimensional linear partial differential equations by finite element methods. This document is intended to guide you through the use of the graphical user interface for interactive use. It assumes that the reader is running MATLAB and the PDE toolbox in a graphical environment.
At the MATLAB prompt, type pdetool. You should see a window like the one below pop up.
We will work through the solution of Laplace's equation with Dirichlet boundary conditions. Solutions of Laplace's equation, called harmonic functions, describe situations in which forces are balanced, as might occur in electrostatics or thermal equilibria. This is an example which might be first encountered in an elementary PDE course, and which you might solve by Fourier series methods, by hand; you will find that you obtain the solution faster with the PDE Toolbox, and that you also obtain a visual representation, which may contribute to the more important goal of understanding. We will then modify the example, to one which might not be so easily done by hand.
- Draw the region of interest: suppose we want the rectangle (x,y) = [0, 3] X [0, 1].
- In the Options menu, select Grid and Snap; then set the Axes' Limits to [-1 4] and [-1 2]. When finished, click Apply and Close the Axes' Limits window.
- In the Draw menu, select Rectangle/Square (not centered).
- In the drawing region, click and hold with the cursor at the origin, and drag it to the point with coordinates (3,1). The region will be shaded and marked R1.
- Set up the boundary conditions: suppose we want the unknown solution function u to be -1 on the long horizontal sides, and +1 on the short vertical sides.
- In the Boundary menu, select Boundary Mode. The window changes to this:
- In the drawing region, double click on the left edge of the rectangle. The boundary condition window pops up. The default Dirichlet condition h*u=r is OK, the default h=1 is OK; change the value of r to +1.
- Do the same thing with the right edge: double-click, set the value. On the top and bottom edges, set r to -1. Be patient and careful. When the boundary conditions are correctly set, you should be able to click on any edge, and see the correct value for r.
- Specify the particular PDE of interest:
- In the PDE menu, select PDE specification. The pde specification window pops up; we are doing the default type of problem, elliptic, of the form -div(c*grad(u)) + a*u = f, where a=0, f=0, and c=1. Change the values as needed, and click on OK.
- Generate the mesh:
- In the Mesh menu, select Initialize Mesh. This time we will use the default mesh.
- Solve the Finite Element problem:
- In the Solve menu, select Solve PDE. The figure in the main drawing area changes.
- Generate other plots:
- In the Plot menu, select Parameters. The plot parameter window pops up; click on the check boxes for color, contour, and height, then on the Plot button.
A new figure window pops up, with the appropriate plot.
Click the Done button [the height plot will remain the default].
The contours are pretty jagged, you may wish to get a better result. Go back to the Mesh menu, and select Refine mesh; Solve again; if you wish, repeat the process. You can click and hold with the left mouse button, and then drag to change the viewing angle.
Let's solve a similar problem: Laplace's equation on the same rectangle, with different boundary conditions.
- Go back to Boundary mode.
- Make the boundary conditions on the short vertical sides be 4*sin(pi*y).^2 .
On the long horizontal sides make it -.05 * x.^4 .* (3 - x).^2 on the bottom, -.05*x.^2.*(3 - x).^4 on the top.
- Then solve and plot, again. This time we have set the plot parameters to color and contour, but not height:
In the figure below, we have again checked the height box in the Plot Parameters window, and under Property, we have made the color vary with abs(grad(u)). You can click on the figure window and drag to obtain a different point of view.
You may want to save your work; click on File, then Save As... Save your session in your own directory, as
pdeintro.m. Then you can quit MATLAB, and at some later time restart it and enter pdeintro at the MATLAB command prompt to return to the current state.
The PDE Toolbox can be used from the command prompt without using the GUI interface illustrated above, or in batch mode using m-files. For example, several demonstration files are included with the package; at the MATLAB command prompt, type pdedemo1 [alternatively, pdedemos brings up a menu window].
The code may be examined, in the
The MATLAB PDE Toolbox is a product of Computer Solutions Europe AB.