MATLAB: I am using the ode15s solver with the cantera’s library. I came across this error (see below) that I don’t know how to solve. Many thanks for the help.

fevalreactor_ode

This is my main code:
y = [20 5 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0];
biopyrolysis = IdealGasMix('biomass_cell.xml');
p = pressure(biopyrolysis);
options = odeset('OutputFcn',{@odeplot,@odeprint});
options = odeset(options,'RelTol',1.e-5,'AbsTol',1.e-9);
tspan = [1 5];
for nt = 1:20;
out = ode15s(@reactor_ode,tspan,y,options,biopyrolysis);
end
and these are my functions:
function dydt = reactor_ode(t,y,gas)
[m,n] = size(y);
dydt = zeros(m,n);
for j = 1:n
this_y = y(:,j);
int_energy = this_y(1);
vol = this_y(2);
masses = this_y(3:end);
% evaluate the total mass, and the specific internal energy and volume.
total_mass = sum(masses);
u_mass = int_energy/total_mass;
v_mass = vol/total_mass;
% set the state of the gas by specifying (u,v,{Y_k})
setMassFractions(gas,masses);
setState_UV(gas, [u_mass v_mass]);
p = pressure(gas);
% volume equation
vdt = feval(@vdot, t, vol, gas);
% energy equation
a = feval(@area, t, vol);
q = feval(@heatflux, t, gas);
udt = -p * vdt + a * q;
% species equations
ydt = total_mass * ydot(gas);
% set up column vector for dydt
dydt(:,j) = [udt
vdt
ydt ];
end
function q = heatflux(t, gas)
q = 0.0;
end
function a = area(t,vol)
a = 1.0;
end
function v = vdot(t, vol, gas)
v = 1.e11 * (pressure(gas) - 101325.0);
end
and the error I get is:
Error using feval
Argument must contain a string or function_handle.
Error in ode15s (line 481)
feval(outputFcn,[t tfinal],y(outputs),'init',outputArgs{:});
Error in test (line 15)
out = ode15s(@reactor_ode,tspan,y,options,biopyrolysis);
But the way I see, all the functions I am using are handle.

Best Answer

The difficulty is in evaluating the OutputFcn, which you have created as {@odeplot,@odeprint} which is a cell array of function handles rather than being one function handle. If you look at https://www.mathworks.com/help/matlab/ref/odeset.html#input_argument_namevalue_OutputFcn you will see that the documented syntax is
[] or @odeplot (default) | function handle
which does not permit a cell array of function handles.