How do I solve coupled PDEs and ODEs together using pdepe?

Hey everyone!
I am trying to use pdepe to solve a system of 6 differential equations. Four of them are PDEs , being first order in time and second order in space. But two of them are ODEs which are first order in time. I want to use pdepe to solve them together since the variables of the two ODEs in the appearance PDEs of the other system variables.
I tried the c values in pdefun of the ODEs to 1 while the f values were set to 0 since I do have any spatial derivative and just a time derivative. And for the ODEs, I set the p and q values in bcfun to zero for both the left and right matrixes (pl,ql,pr and qr) since there are no BCs defined for the variables.
But my simulation is failing and I getting an error saying that my spatial discretization has failed.
Lemme know if anyone has info that could help me out or need any additional information from my end!
Best,
Manu

 Accepted Answer

The usual setting in this case is
c = 1
f = 0
s = according to your ODE
pl = 0
pr = 0
ql = 1
qr = 1
for the ODEs.
This can lead to discrepancies in the boundary points if the PDE boundary conditions depend on the values of the ODEs.
pdepe is usually designed to solve parabolic-elliptic PDEs, not hyperbolic PDEs or ODEs. So strictly speaking, it's not suited to solve your problem. But you can test the described procedure. Or use https://uk.mathworks.com/matlabcentral/fileexchange/97437-pde1dm - I think it can handle coupled ODEs.

1 Comment

I tried the set of values you mentioned and my simulation did run without any error. My PDE boundary conditions are simple Dirichlet and Neumann conditions for the respective dependent variables and are not intertwined with the ODEs, if that is what you were referring to.
Never knew about pde1dm, that will be helpful for me in the future.
Thanks for your help!

Sign in to comment.

More Answers (0)

Products

Release

R2024b

Asked:

on 22 Mar 2026

Commented:

on 22 Mar 2026

Community Treasure Hunt

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

Start Hunting!