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

采纳的回答

Andrew Newell
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
Thibaut 2011-3-30
Hi.
I can compile and get results but it turns out that the results are not as they are expected to be. The plot of q(r=R,t) - i.e. the computed parameter at the defined right boundary - should be oscillating. It turns out it is not. This oscillation should result from the definition of Pr (the right boundary) in the file q_pde_bc (see first post, above) which in turn relies on qs.
I think I made a mistake in the way I defined this boundary condition and/or in the way I defined the vector qs but I can't find what exactly is wrong and thus can't find the solution either.
Can anyone see what the mistake is? And what the solution can be?
Thanks for your help.
  2 个评论
Andrew Newell
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?
Thibaut
Thibaut 2011-3-30
I uploaded it through my Mathworks account. I will post the link as soon as it gets reviewed and accepted.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by