Finite Difference solution to nonlinear diffusion equation

Numerical solution to nonlinear diffusion equation and creates movie of results


Updated 18 Jun 2015

View License

Solves nonlinear diffusion equation which can be linearised as shown for the general nonlinear diffusion equation in Richtmyer & Morton [1]. The approach is to linearise the pde and apply a Crank-Nicolson implicit finite difference scheme to solve the equation numerically.
Matlab run command


solves the pde:

\frac{\partial h}{\partial t}=\frac{1}{12}\frac{\partial^2 h^4}{\partial x^2}

The pde has the application to isothermal viscous fluid flow spreading on a horizonatal substrate under gravity - Huppert [2]. Note that PDE has been nondimensionlised.

Initial conditions:

t=0: h = (1 - x^2)_{+} + 10^-6 (has prewetting film)

The spatial domain is discretised taking account of symmetry at x = 0:

\frac{\partial h}{\partial x} = 0

and is also used to close the free surface model at the end of the discretised domain (x = xend) - assumes fluid won't reach this boundary.

The pde can be solved analytically using similarity equations as discussed by Barenblatt [3]; used below to validate numerical solution.


[1] "Difference Methods for initial value problems," R. D. Richtmyer and K. W. Morton, John Wiley and Sons, 1967.

[2] "The Propagation of two-dimensional and axisymmetric visous gravity currents over a rigid horizontal surface," H. E. Huppert, Journal of Fluid Mechanics, 1982.

[3] "On some unsteady motions of a liquid or gas in a porous medium, Russian journal Prikladnaya Matematika i Mekhanika, 1952.

Cite As

Ahmos Sansom (2023). Finite Difference solution to nonlinear diffusion equation (, MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2015a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes

Updated for 2015