필터 지우기
필터 지우기

Passing Structure Array of Parameters into Boundary Condition Function for PDEPE

조회 수: 10 (최근 30일)
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

채택된 답변

Stephen23
Stephen23 2020년 10월 13일
편집: Stephen23 2020년 10월 13일
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
Stephen23
Stephen23 2020년 10월 13일
"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.
Myles Stapelberg
Myles Stapelberg 2020년 10월 13일
Great this clears things up for me. Thank you Stephen!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Eigenvalue Problems에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by