issue with pdepe: "Spatial discretization has failed."

I am trying to solve the system of coupled partial differential equations described in the attachment using the function pdepe. My code runs into this error:
Error using pdepe (line 293)
Spatial discretization has failed. Discretization supports only parabolic and elliptic equations, with flux term involving
spatial derivative.
Error in pde_ex (line 7)
sol = pdepe(0,@main,@initial,@bound,x,t);
Here's the code I'm using:
function pde_ex
clc;
dt = 100;
tmax=10^5;
t = 0:dt:tmax;
x = t/tmax;
sol = pdepe(0,@main,@initial,@bound,x,t);
u1 = u(:,:,1)
u2 = u(:,:,2)
% -----------------------
function [c,f,s] = main(x,t,u,dudx)
c = [1; 1];
f = [1; 1].*dudx;
s1 = -1*((1+[0, 1]*u))*([1, 0]*u)*(1+[0, 1]*u);
s2 = -1*([0, 1]*u) + ([1, 0]*u)/(1+[1, 0]*u);
s=[s1;s2];
% -----------------------
function [pa,pb,qa,qb] = bound(xa,ua,xb,ub,t)
pa = [-1; 0];
qa = [1; 1];
pb = [0; 0];
qb = [1; 1];
% -----------------------
function u0 = initial(x)
u0=[0; 0];
What I've seen in answers to similar questions is that the boundary conditions might not be implemented correctly (e.g. /answers/169414-spatial-discretization-has-failed-pdex1). I've checked this but haven't been able to find the error. If not that, I'm unsure what this error means and how to fix it.
Any help would be much appreciated.

3 Comments

"s1" and "pa" are not correctly set if you want to solve the equations posted in pde_ex.pdf.
Best wishes
Torsten.
Thanks. The original equations were a bit more cumbersome and I tried to simplify them somewhat before posting this - s1 should have been:
s1 = -1*([0, 1]*u)*([1, 0]*u)*(1+[1, 0]*u);
and pa = [1;0]; but that does not solve the problem.
As for pa: the spatial discretization works when I use:
function [pa,pb,qa,qb] = bound(xa,ua,xb,ub,t)
pa = ua-[-1; 0];
qa = [1; 1];
pb = ub-[0; 0];
qb = [1; 1];
But I'm not sure why one would define pa and pb as such. Is there a more thorough documentation available on how pdepe handles boundary conditions than [help/matlab/ref/pdepe.html#f93-998749]?
Setting pa and pb as above does not define the problem you are trying to solve.
My guess is that the problem occurs because you only prescribe gradients at the boundaries. On the other side, I don't see why this should not be possible.
Best wishes
Torsten.

Sign in to comment.

Answers (1)

Beyond the problems already mentioned by Torsten, the reason for the error message is that you have listed the returned arguments from the bound function incorrectly. It should be:
function [pa,qa,pb,qb] = bound(xa,ua,xb,ub,t)
Your initial conditions and your boundary conditions are inconsistent but this should not prevent pdepe from obtaining a "solution."
Finally, for future reference, it would make your code much easier to debug if you wrote it in a simpler and more direct way, e.g.
u1=u(1,:);
u2=u(2,:);
f=dudx;
s1 = -u2.*(u1+u1.^2);
s2 = -u2 + u1./(1+u1);

Asked:

on 26 Mar 2018

Answered:

on 26 Mar 2018

Community Treasure Hunt

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

Start Hunting!