MATLAB Answers

Error in using MATLAB PDEPE function - incorrect matrix sizing

1 view (last 30 days)
Sarah Snader
Sarah Snader on 14 Apr 2018
Commented: Torsten on 16 Apr 2018
Hello!
I am having some issues modifying the code on Matlab Example 2 pdex4 function on the PDEPE help page. I believe the problem is incorrectly sized matrices, but I am not sure where I should be using '.*' vs'*'.
function [x,t,u1, u2]=pdex4attempt(dummy)
close all;
m = 0;
x = [0 0.005 0.01 0.05 0.1 0.2 0.5 0.7 0.9 0.95 0.99 0.995 1];
t = [0 0.005 0.01 0.05 0.1 0.5 1];
sol = pdepe(m,@pdex4pde,@pdex4ic,@pdex4bc,x,t);
u1 = sol(:,:,1);
u2 = sol(:,:,2);
% --------------------------------------------------------------
function [c,f,s] = pdex4pde(x,t,u,DuDx)
Pe=1000;
gamma=2;
phi=0.4;
c = [Pe; 1];
f = [DuDx-Pe.*u(1); 0];
F=(gamma.*u(1)-u(2));
s = [-((1-phi)/phi)*F*Pe; F];
end
% --------------------------------------------------------------
function u0 = pdex4ic(x)
u0 = [0; 0];
end
% --------------------------------------------------------------
function [pl,ql,pr,qr] = pdex4bc(xl,ul,xr,ur,t)
Pe=1000;
beta=0;
pl = [ul(1); 0];
ql = [0; 0];
pr = [-beta+Pe.*ur(1); 0];
qr = [1; 0];
end

  1 Comment

Torsten
Torsten on 16 Apr 2018
pdepe is designed to solve parabolic-elliptic PDEs, not a mixture of ODEs and PDEs as in your case.

Sign in to comment.

Answers (1)

Bill Greene
Bill Greene on 14 Apr 2018
The line
f = [DuDx-Pe.*u(1); 0];
is creating a variable f with three rows rather than the correct two rows because DuDx, itself, is dimensioned 2x1. Since you didn't post your equations it is impossible to say what is the correct expression. Do you perhaps want DuDx(1) instead of just DuDx?

  0 Comments

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!