issue with pdepe: "Spatial discretization has failed."

1 view (last 30 days)
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
Torsten
Torsten on 26 Mar 2018
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)

Bill Greene
Bill Greene on 26 Mar 2018
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);

Categories

Find more on Results, Reporting, and Test File Management in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!