## 8. Examples of problems solved with Matlab

#### 8.1 Matrix examples 8.1.1 Largest eigenvalue of a random dispersion matrix 8.1.2 8.2 Partial differential equations 8.2.1 Solve a semi-linear heat equation 8.2.2 Solve the Cahn-Hilliard equation 8.3 Optimization 8.3.1 8.4 Inverse problems 8.4.1

The following examples are intended to help you gain ideas about how Matlab can be used to solve mathematical problems.

### 8.2 Partial differential equations

#### 8.2.2 Solving the Cahn-Hilliard equation

The Cahn-Hilliard equation is a central equation in theoretical materials science, and its importance has been compared with the Navier-Stokes equation in several research publications. The equation itself is a fourth order nonlinear parabolic partial differential equation. Solving the Cahn-Hilliard equation numerically is difficult because the equations are "stiff". Roughly speaking this means that the dynamics of the equation take place on numerous time scales, and so explicit methods for solving the equation are extremely unstable.

This code utilizes a time marching method for solving the Cahn-Hilliard equation that is unconditionally stable (paper). Without such a method, solving the Cahn-Hilliard equation for long times is a very slow process. To run the code, either save the code in a .m file and execute that file in Matlab (it doesn't need any additional arguments) or cut and paste.

The code generates a movie of the solution, so don't raise a window over the figure or movie will not work properly. The movie has 25 frames, and the code takes 250 time steps.

The data is presented with four subplots, the top two plots show the solution as a function of space. The lower left plot shows a cross section of the solution, and the lower right plot shows a portion of the power spectrum of the solutions cosine transformation.

By studying the code, you should be able to use similar ideas in your applications.

David Eyre
9/8/1998