# pdefun must return 3 column vectors?

4 views (last 30 days)
Dayna Grimshaw on 16 Jul 2018
Hi,
I'm trying to solve the 1D heat equation using the pdepe function and keep getting 2 errors, the first says "Unexpected output of PDEFUN. For this problem PDEFUN must return three column vectors of length 500.", and the second is "Error in line 7: sol = pdepe(m,@heatpde,@heatic,@heatbc,x,t);". The second one I can't see a problem with since it's the correct format I can't see any differences between my code and the examples in matlab documents...
Here's my code:
%% Using the PDEPE command to solve the 1D heat equation
x = linspace(0,100,500);
t = linspace(0,10,50);
m = 0;
sol = pdepe(m,@heatpde,@heatic,@heatbc,x,t);
u = sol(:,:,1);
%%%%%%%%%%%%%%%%
function [c,f,s] = heatpde(x,t,u,DuDx)
c = 0.2;
f = DuDx;
s = 0;
end
%%%%%%%%%%%%%%%%
function u0 = heatic(x)
u0 = [100 zeros(1,498) 50]';
end
%%%%%%%%%%%%
%% set boundary conditions
function [pl,ql,pr,qr] = heatbc(xl,ul,xr,ur,t)
pl = ul;
ql = 0;
pr = pi*exp(-t);
qr = 1;
end

R2017b

### Community Treasure Hunt

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

Start Hunting!