issue with pdepe: "Spatial discretization has failed."

5 次查看(过去 30 天)
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 个评论
Mart Last
Mart Last 2018-3-26
编辑:Mart Last 2018-3-26
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]?
Torsten
Torsten 2018-3-26
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.

请先登录,再进行评论。

回答(1 个)

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

类别

Help CenterFile Exchange 中查找有关 Performance and Memory 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by