I am trying to use Matlab's pdepe.m to solve the first order parabolic PDE $$\frac{\partial u}{\partial x}+\frac{\partial u}{\partial x}=x$$ I have not had trouble coding the argument of pdepe @pdefun:
function [c,f,s] = pdefun(x,t,u,DuDx)
c = 1;
f = -u;
s = x;
end
Since this is first order in space and time, we have one boundary condition and one initial condition. pdepe takes as an argument @bcfun(xl,ur,xr,ur,t), which has two boundary conditions. I understand for a unique solution to a PDE that is second order in space we would need two boundary conditions. However, given that this first order PDE can be expressed with pdepe, I would expect there is a way to code in only a single boundary condition, since a second boundary condition would overconstrain the solution.
I have tried coding in a single boundary condition as follows:
function [pl,ql] = pdebc(xl,ul,t)
pl = ul;
ql = 0;
end
But Matlab gives the error:
Error using prob1pdepe
Too many input arguments.
Error in pdepe (line 250)
[pL,qL,pR,qR] = feval(bc,xmesh(1),y0(:,1),xmesh(nx),y0(:,nx),t(1),varargin{:});
Is there a way to solve PDEs of this type with pdepe? If so, how do I deal with @bcfun in a way that does not overconstrain the problem?
My full code is shown below
clearvars; close all; clc
% definitions
x = linspace(0,10,256); % mesh with L=1
t = linspace(0,50,256);
sol = pdepe(0,@(x,t,u,DuDx)pdedef(x,t,u,DuDx),@(x)pdeic(x),@(xl,ul,t)pdebc(xl,ul,t),x,t);
function [c,f,s] = pdedef(x,t,u,DuDx)
c = 1;
f = -u;
s = x;
end
% % % % % % % % % % % % % % % % % % % % % % %
function u0 = pdeic(x)
u0 = 0;
end
% % % % % % % % % % % % % % % % % % % % % % %
function [pl,ql] = pdebc(xl,ul,t)
pl = ul;
ql = 0;
end
I've tried a number of variations including of how I call the bcfun including
sol = pdepe(0,@(x,t,u,DuDx)pdedef(x,t,u,DuDx),@(x)pdeic(x),@(xl,ul,xr,ur,t)pdebc(xl,ul,t),x,t);
which gives the following error:
Error using prob1pdepe>pdebc
Too many output arguments.
Error in prob1pdepe (line 6)
sol = pdepe(0,@(x,t,u,DuDx)pdedef(x,t,u,DuDx),@(x)pdeic(x),@(xl,ul,xr,ur,t)pdebc(xl,ul,t),x,t);
Error in pdepe (line 250)
[pL,qL,pR,qR] = feval(bc,xmesh(1),y0(:,1),xmesh(nx),y0(:,nx),t(1),varargin{:});
I've tried making bcfun take the arguments xr and ur but do nothing with them:
function [pl,ql] = pdebc(xl,ul,xr,ur,t)
pl = ul;
ql = 0;
end
When I do this, the error message is
Error using prob1pdepe>pdebc
Too many output arguments.
Error in prob1pdepe (line 6)
sol = pdepe(0,@(x,t,u,DuDx)pdedef(x,t,u,DuDx),@(x)pdeic(x),@(xl,ul,xr,ur,t)pdebc(xl,ul,xr,ur,t),x,t);
Error in pdepe (line 250)
[pL,qL,pR,qR] = feval(bc,xmesh(1),y0(:,1),xmesh(nx),y0(:,nx),t(1),varargin{:});
for both of the ways I called @bcfun in pdepe.
Any advice would be great. Thanks!