Passing Structure Array of Parameters into Boundary Condition Function for PDEPE

15 views (last 30 days)
Hello,
I am trying to use PDEPE, and have many constants that I would like to pass to my Boundary Condition Function via a structure array. I followed the instructions for the "Solve PDE and Compute Partial Derivatives" Example, but when I try to pass in the Structure Array "C" into my BC function "magBC", I get:
Not enough input arguments.
Error in ParametricCode>magBC (line 127)
I_0 = C.I_0;
Error in pdepe (line 250)
[pL,qL,pR,qR] = feval(bc,xmesh(1),y0(:,1),xmesh(nx),y0(:,nx),t(1),varargin{:});
Error in ParametricCode (line 21)
sol = pdepe(m,eqn,ic,@magBC,x,t);
How would I pass my Parameters into the Boundary condition? Here is the function for reference:
function [pl,ql,pr,qr] = magBC(xl,ul,xr,ur,t,C)
I_0 = C.I_0;
delta = C.delta;
R_0 = C.R_0;
r_w = C.r_w;
pl = ul - I_p(t)/I_0 * (log(8*R_0/r_w) - 2 );
ql = 0;
pr = ur;
qr = 1/delta * (log(8*R_0/(r_w*(1+delta))) - 2 ); %removed (1 + delta)
% from numerator
% because we have it
% in the definition
% for f in the kernel
end
Would taking out the xl and xr terms, or filling them in with the first and land entries of by x mesh work? It seems that the magBC function isn't taking in my C structure, and after fidding around, I am unable to get the constants to pass into the BC function like I have with the others.
Thanks,
Myles

Accepted Answer

Stephen23
Stephen23 on 13 Oct 2020
Edited: Stephen23 on 13 Oct 2020
You need to parameterize the function:
Usually the simplest approach is to use an anonymous function, e.g.:
C = ..; % define parameters here
fun = @(xl,ul,xr,ur,t) magBC(xl,ul,xr,ur,t,C); % anonymous function
sol = pdepe(m,eqn,ic,fun,x,t);
  3 Comments
Stephen23
Stephen23 on 13 Oct 2020
"What's actually happening when I call: fun = @(xl,ul,xr,ur,t) magBC(xl,ul,xr,ur,t,C);?"
You define an anonymous function with five input arguments (which is exactly what pdepe requires) inside of which you happen to call magBC with six input arguments. The value of C is taken from the workspace at the point when the anonymous function is created.
"Do we only have to pass in xl,ul,xr,ur, and t because they change?"
Sort of: the pdepe documentation states that its fourth input must be a function having five input arguments, so of course that is what we have to provide it with. Whether those input values "change" or not depends on whatever pdepe does with them when it calls that function.
"Where as C doesn't and can just be pased directly into the magBC function?"
Yes.

Sign in to comment.

More Answers (0)

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!