Solving Partial Differential Equations in MATLAB

MATLAB Illustration

MATLAB offers two main approaches for solving partial differential equations (PDEs):

  1. pdepe – Built-in solver for 1-D parabolic and elliptic PDEs in one spatial variable (x) and time (t). Suitable for heat conduction, diffusion, wave equation, and reaction-diffusion systems.
  2. Partial Differential Equation Toolbox – Uses finite element method (FEM) for 2-D and 3-D problems (structural mechanics, heat transfer, electromagnetics, general scalar/vector PDEs).

Using pdepe (1-D PDEs)

PDE must be written in the standard form: c(u,x,t) * ∂u/∂t = ∂/∂x [ f(u,x,t,u_x) ] + s(u,x,t,u,u_x)

Steps:

  1. Define PDE coefficients in a function [c,f,s] = mypde(x,t,u,dudx).
  2. Define initial condition u0(x) = myic(x).
  3. Define boundary conditions [pl,ql,pr,qr] = mybc(xa,ua,xb,ub,t).
  4. Create spatial and time meshes: x = linspace(0,1,50); t = linspace(0,1,100);.
  5. Solve: sol = pdepe(m, @mypde, @myic, @mybc, x, t); (m = 0 for slab/Cartesian, 1 cylindrical, 2 spherical).
  6. Extract solution: u = sol(:,:,k) for k-th equation.
  7. Plot: surf(x,t,u) or pcolor(x,t,u).

Using Partial Differential Equation Toolbox (2-D/3-D)

Steps:

  1. Create model: model = createpde(N); (N = number of equations).
  2. Define geometry (built-in shapes, CSG, or import STL).
  3. Specify PDE coefficients (c, a, f, d terms).
  4. Apply boundary conditions (Dirichlet, Neumann, generalized).
  5. Generate mesh: generateMesh(model);.
  6. Solve:
    • Stationary: result = solvepde(model);
    • Transient: solvepdetransient
    • Eigenvalue: solvepdeeig
  7. Visualize: pdeplot(model,'XYData',u,'Contour','on'); or pdeplot3D.

Ideal for engineering and physics simulations.

Verified Feedback

What Engineering Students Say

Real feedback from students across top engineering universities worldwide.

Verified Student

“I got full marks on my MATLAB DSP assignment! The filter design code was completely vectorized, the frequency response plots were exact, and the delivery was 8 hours before my deadline. Highly recommended!”

AS

Aditi Sharma

IIT Bombay • Signal Processing Coursework
Verified Student

“Our Simulink EV powertrain model had severe algebraic loop and solver errors. The MATLABSolutions team fixed the solver configuration in 4 hours and provided an annotated scope diagram. Lifesaver for my final year!”

JM

John M.

Monash University, Australia • Simulink Dynamic Model
Technical Knowledge Base

Latest MATLAB Guides & Tutorials

Explore deep-dive technical articles written by our engineering team to master complex MATLAB & Simulink topics.

MATLAB Guide 5 Min Read

Physics-Informed Neural Networks (PINNs) for Microgrid Dynamics and Power Flow in MATLAB

Modern microgrids operate with low physical inertia, rapid inverter switching dynamics, and intermittent renewable power generation. Simulating these systems requir...

MATLAB Guide 5 Min Read

ROS 2 and MATLAB Co-Simulation for Autonomous Mobile Robot Path Tracking Using NMPC

Tracking complex trajectories with non-holonomic mobile robots requires handling physical constraints such as actuator saturation, wheel slip, and sharp cornering. Standard cont...