Why do I get the error '' too many input argument''?

1 view (last 30 days)
I'm try to define the stepchange of bc in pdepe which pl varies with time. The following is my code.
Can anyone help? plzzzz...
T = 16; % maximum time [s]
L = 8; % length [m]
D = 0.1; % diffusivity [m*m/s]
v = 0.5; % real fluid velocity [m/s]
theta = 0.2; % porosity
rhob = 1200; % porous medium bulk density [kg/m*m*m]
kappaf = 0.00; % transition rate fluid to solid [1/s]
kappas =0.1; % transition rate solid to fluid [1/s]
lambdaf = 0; % decay rate in fluid [1/s]
lambdas = 0; % decay rate in solid [1/s]
c0f = 1; % initial concentration in fluid [kg/m*m*m]
c0s = 0.1; % initial concentration in solid [1]
M = 100; % number of timesteps (>2)
N = 40; % number of nodes
%-------------------------- output parameters------------------------------
gplot = 1; % =1: breakthrough curves; =2: profiles 1
t = linspace (T/M,T,M); % time discretization
x = linspace (0,L,N); % space discretization
cin = 10; % inflow concentration [kg/m*m*m]
bctimes=[0,5,5.1,T];
bcVals=[cin,cin,0,0];
%----------------------execution-------------------------------------------
bcFunc=@(xl,ul,xr,ur,t) slowsorpbc(xl,ul,xr,ur,t,bctimes,bcVals);
options = odeset;
c = pdepe(0,@slowsorpde,@slowsorpic,bcFunc,x,t,options,D,v,theta,rhob,kappaf,kappas,lambdaf,lambdas,[c0f;c0s]);
%---------------------- graphical output ----------------------------------
Y=c(:,N,1);
switch gplot
case 1
plot (t,c(:,N,1)) % breakthrough curves
xlabel ('time'); ylabel ('concentration');
case 2
plot (x,c(:,:,2)','--') % profiles
xlabel ('space'); ylabel ('concentration');
end
% --------------------------------------------------------------------------
function [c,f,s] = slowsorpde(x,t,u,DuDx,D,v,theta,rhob,kappaf,kappas,lambdaf,lambdas,c0)
c = [1;1];
f = [D;0].*DuDx;
s = -[v;0].*DuDx - [lambdaf;lambdas].*u - ([kappaf,-kappas]*u)*[1/theta;-1/rhob];
end
% --------------------------------------------------------------------------
function u0 = slowsorpic(x,D,v,theta,rhob,kappaf,kappas,lambdaf,lambdas,c0)
u0 = c0;
end
% --------------------------------------------------------------------------
function [pl,ql,pr,qr] = slowsorpbc(xl,ul,xr,ur,t,bctimes,bcVals)
pl = [ul(1)-interp1(bctimes,bcVals,t);0];
ql = [0;1];
pr = [0;0];
qr = [1;1];
end
  3 Comments
Yi Peng Biao
Yi Peng Biao on 16 Aug 2020
Edited: Yi Peng Biao on 16 Aug 2020
sorry, here's the error message.
Error using slowsorp001>@(xl,ul,xr,ur,t)slowsorpbc(xl,ul,xr,ur,t,bctimes,bcVals)
Too many input arguments.
Error in pdepe (line 250)
[pL,qL,pR,qR] = feval(bc,xmesh(1),y0(:,1),xmesh(nx),y0(:,nx),t(1),varargin{:});
Error in slowsorp001 (line 28)
c =
pdepe(0,@slowsorpde,@slowsorpic,bcFunc,x,t,options,D,v,theta,rhob,kappaf,kappas,lambdaf,lambdas,[c0f;c0s]);
Walter Roberson
Walter Roberson on 19 Aug 2020
Harshendra Shah: the documentation is slightly misleading. Additional arguments to pdepe are possible... they just are no longer documented. They have not been documented for since around MATLAB 5.3...

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 19 Aug 2020
Although it is no longer documented, for backwards compatibility, if you pass extra arguments to pdepe(), then it attempts to pass those extra arguments to every function it invokes your your behalf.
You are passing the 9 extra arguments D, v, theta, rhob, kappaf, kappas, lambdaf, lambdas, [c0f;c0s] so your bcFunc and other functions that you pass in need to accept 9 extra input arguments besides what they normally take. So in the case of bcFunc which expects 5 inputs normally, the function handle you supply would have to accept 5+9 = 14 input arguments.
It is not recommended that you write any new code taking advantage of this old feature. There are already some subtle incompatibilities between it and some functions such as fmincon about what is expected to happen if you try to take advantage of leaving off some trailing inputs to the major function being invoked, but at the same time want to pass in extra inputs to the function handles.
The recommended approach is to instead parameterize your functions as needed, and not pass any extra arguments to pdepe using the undocumented feature.
You already have a good example of parameterization:
bcFunc=@(xl,ul,xr,ur,t) slowsorpbc(xl,ul,xr,ur,t,bctimes,bcVals);
That is a generally a good design.
  1 Comment
Yi Peng Biao
Yi Peng Biao on 21 Aug 2020
Thanks for your answer. I found the problem in my code. Thnak you very much.

Sign in to comment.

More Answers (0)

Categories

Find more on Fluid Dynamics in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!