MATLAB Answers

0

pdefun must return 3 column vectors?

Asked by 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
Thanks in advance for your help!

  0 Comments

Sign in to comment.

Products


Release

R2017b

0 Answers