MATLAB: Passing Structure Array of Parameters into Boundary Condition Function for PDEPE

function handlesMATLABpdepestructure arrays

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

Best Answer

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);