MATLAB: Error using pdepe to solve PDE

khaznah alkhaldi

Unexpected output of PDEFUN. for this problem PDEFUN must return three column vectors of length 2
Error in solve (line 13)
solution = pdepe(m,@pdefun,@icfun,@bcfun,x,t)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [c,f,s] = pdefun(x,t,u,DuDx)
c = []; f = [0.024;0.170].*DuDx;
y = u(1)-u(2) ;
F = exp(5.73*y)-exp(-11.46*y);
s = [-F,F];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [pl,ql,pr,qr]=bcfun(x1,u1,xr,ur,t)
pl = [0;u1(2)]; ql = [1;0];
pr = [ur(1)-1;0]; qr = [0;1];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function u0 = infun(x)
u0 = [1;0];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
m =0 ;
x = [0 0.005 0.01 .05 .1 .2 .5 .7 .9 .95 .99 .995 1];
t = [0 .005 .01 .05 .1 .5 1 1,5 2];
solution =pdepe(m,@pdefun,@icfun,@bcfun,x,t);
u1 = solution(:,:,1);
u2 = solution(:,:,2);
figure(1)
surf(x,t,u1)
figure(2)
surf(x,t,u2)

Best Answer

"The input arguments are scalars x and t and vectors u and dudx that approximate the solution u and its partial derivative with respect to x, respectively. c, f, and s are column vectors. c stores the diagonal elements of the matrix c"
In your code
s = [-F,F];
is a row matrix, not a column matrix.
The message hints that your c will need to be a column vector of length 2 as well, whereas at the moment it is empty.
Related Question