Question
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
Expert Answer
Prashant Kumar
PhD Expert
Answered Aug 30, 2026
In older MATLAB versions, passing extra trailing arguments directly into pdepe() caused the solver to forward those values to every callback function it evaluated. If you pass 9 additional variables (D, v, theta, rhob, kappaf, kappas, lambdaf, lambdas, and [c0f;c0s]), your boundary function bcFunc must accept 14 inputs (5 standard inputs + 9 extra) instead of the standard 5.
Avoid relying on this legacy behavior in modern MATLAB scripts for several reasons:
- Deprecated syntax: MathWorks no longer documents or supports passing parameter lists as trailing arguments to solvers.
- Solver incompatibilities: Trailing arguments create conflicts across toolboxes (such as in
fmincon) when default or optional arguments are left blank.
- Bloated function signatures: Every subfunction is forced to accept every variable, even if only one callback needs it.
Recommended Solution: Parameterize with Anonymous Functions
The standard, robust method in MATLAB is to wrap your helper functions in anonymous function handles. This lets each function capture only the specific workspace variables it requires without changing the solver signature.
Your parameterization syntax is the correct design pattern:
bcFunc = @(xl, ul, xr, ur, t) slowsorpbc(xl, ul, xr, ur, t, bctimes, bcVals);
This keeps function definitions clean, explicit, and fully compatible across all current and future MATLAB releases.
100% Run Guarantee
3-Hour Fast-Track Delivery
Need a Custom Version or Complete Simulation for This Problem?
Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.
Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee