Finite Difference solution to nonlinear diffusion equation
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
--------------------------
type:
IsoFreeSurfaceSolver
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.
References
--------------
[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 (2025). Finite Difference solution to nonlinear diffusion equation (https://www.mathworks.com/matlabcentral/fileexchange/27890-finite-difference-solution-to-nonlinear-diffusion-equation), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxCategories
- Mathematics and Optimization > Optimization Toolbox > Nonlinear Optimization >
- Mathematics and Optimization > Partial Differential Equation Toolbox > General PDEs > Visualization >
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.