problem solving a partial differential equation using pdepe
6 次查看(过去 30 天)
显示 更早的评论
Hello.
I'm trying to solve a partial differential equation of the type that can be solved with pdepe. I based my code on the one I found in the Help. The only trick of my code is that one of the boundary conditions contains a time-dependent parameter that has to be numerically determined ("qs" below). My code is the following:
Variables that have to be defined in the Command Window:
sigma = 0;
DC = 5.82E-12;
R = 1E-5;
t = 0:1000;
A = [0.610, -0.238, 0.093];
c_in = 2/3 .* cos(0.01 .* t);
c = c_in;
Then, the main file looks like this:
function q = q_mpd_km(sigma, R, t)
r = linspace(0, R, 20);
sol = pdepe(sigma, @q_pde_de, @q_pde_ic, @q_pde_bc, r, t);
q = sol(:,:,1);
with the following file containing the differential equation:
function [c, f, s] = q_pde_de(r, t, q, DqDr)
global DC
c = 1;
f = DC .* DqDr;
s = 0;
the one with the initial condition:
function q = q_pde_ic(r)
q = 0;
and the one containing the boundary conditions:
function [Pl, Ql, Pr, Qr] = q_pde_bc(rl, ql, rr, qr, t)
global DC A c
qs = zeros(1, length(t));
S = zeros(1, length(A));
for i = 1:length(t)
for j = 1:length(A)
S(j) = A(j) .* c(i).^j ;
end
qs(i) = sum(S);
end
Pl = 0;
Ql = 1 ./ DC;
Pr = qr - qs;
Qr = 0;
As I enter
q = q_mpd_km(sigma, R, t);
in the Command Window, I get the following error message:
??? Attempted to access qL(1); index out of bounds because numel(qL)=0.
Error in ==> pdepe at 269
if qL(j) == 0
Error in ==> q_mpd_km at 13
sol = pdepe(sigma, @q_pde_de, @q_pde_ic, @q_pde_bc, r, t);
I looked at the pdepe file (line 269) but it does not help much! Can you help me? Does this qL have anything to do with my parameter Ql? If not, what is it? Thank for your help.
Tibo
0 个评论
采纳的回答
Andrew Newell
2011-3-24
The problem is that you use global variables in your functions without declaring them in your command window first. Put
global DC A c
before you assign values to DC, etc. Otherwise you'll just get empty values inside your functions (and hence some parameter qL with nothing in it).
更多回答(1 个)
Thibaut
2011-3-30
2 个评论
Andrew Newell
2011-3-30
@Thibaut, unless I see the equations you're trying to solve, I don't know if the code is right or wrong. Nor do I know whether it is a MATLAB issue or a problem with the math itself. Can you post a link to a PDF with the equations in it?
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!