MATLAB: Spatial discretization has failed. Discretization supports only parabolic and elliptic equations, with flux term involving spatial derivative

pdepe

function[phi,potential]=pdex4EEpC(kVal,lVal)
m = 0;
x = linspace(0,4,100);
t = linspace(0,2,500);
nt=length(t);
potential=zeros(nt,1);
for i=1:nt
potential(i)=appPot(t(i));
end
global K L tspan
K=kVal;
L=lVal;
tspan=t;
options = odeset('RelTol',1e-9,'AbsTol',1e-9);
sol = pdepe(m,@pdex4pde,@pdex4ic,@pdex4bc,x,t,options);
u1 = sol(:,:,1);
phi = zeros(1,nt);
for j = 1:nt
% At time t(j), compute Du/Dt at x = 0.
[~,phi(j)] = pdeval(m,t,u1(j,:),0);
end
figure
plot(potential,phi)
title('CV Plot')
xlabel('Potential')
ylabel('Current')
% --------------------------------------------------------------


function [c,f,s] = pdex4pde(x,t,u,DuDx)
global K L
c = [1; 1; 1];
f = [1; 1; 1] .* DuDx;
s = [u(2)-K*u(3)*u(1); -u(2)+K*u(1)*u(3); u(2)-K*u(1)*u(3)-L*u(3)];
% --------------------------------------------------------------
function u0 = pdex4ic(x)
u0 = [1; 0; 0];
% --------------------------------------------------------------
function [pl,ql,pr,qr] = pdex4bc(xl,ul,xr,ur,t)
zeta = overPot(t);
conP = 1/(1+exp(zeta));
conQ = 1/(1+exp(-zeta));
pl = [ul(1)-conP;ul(2)-conQ;0];
ql = [0;0;1];
pr = [ur(1)-1; ur(2);0];
qr = [0; 0; 0];
% Defined as functions in the directory
function [e]=appPot(t)
t0=1;
Ei=-2;
Ef=2;
v=Ef-Ei;
if t<t0
e=Ei+(v*t);
else
e=Ef-(v*(t-t0));
end
end
% Defined as function in the directory
function [zeta]=overPot(t)
E0=1.2;
E=appPot(t);
zeta = (25.693*0.001)*(E-E0);

Best Answer

You forgot to define the boundary condition of the third equation in xr.
Best wishes
Torsten.