MATLAB: Error using odearguments, Inputs must be floats, namely single or double ?? ODE15s

error

Hi, I'm plotting a graph which involve differencial equation at which i'm using ODE15s to solve it.
But no matter how I check, i couldn't find any errors.
Can someone help me?
Here is my code
The main files
alpha = 1000; % Solution density correlation parameter (kg/m^3)

beta = 1100; % Solution density correlation parameter (kg/m^3)
H1 = 3; % Total tank height (m)
H2 = 2; % Height of top zone of tank (m)
L = 3; % Tank width (and length) (m)
CV = 0.256; % Outlet valve coefficient ((m^3/s)/(kPa/(kg/m^3))^0.5)
deltaP = 300; % Pressure drop over control valve (kPa)
Bc = 0.5; % Controller bias (-);
Kc = -5; % Controller gain (-)
taus = 10; % Level sensor time constant (s)
Ga = 1; % Actuator gain (-)
taua = 20; % Actuator time constant (s)
xia = 0.8; % Actuator damping factor (-)
tf = 2400; % Final simulation time (s)
MW0 = 16750; % Initial mass of water in tank (kg)
MB0 = 7150; % Initial mass of boganite in tank (kg)
hs0 = 2.5; % Initial level sensor reading (m)
w0 = 0; % Initial scaled valve stem velocity (1/s)
S0 = 0.5; % Initial dimensionless valve position (-)
%

% Pack the Parameters into single Pack
p = {alpha, beta, H1, H2, L, CV, deltaP, Bc, Kc, taus, Ga, taua, xia};
% Pack up the initial conditions
y0 = [MW0 MB0 hs0 w0 S0];
tspan = [0 tf];
[t,y] = ode15s(@(t,y) mass(t,y,p), tspan, y0);
and another files
mass.m which is my function files
function dmdt=mass(t,y,p)
% Function of dM/dt, solving change of total mass over changing
% time
% Unpacking the initial condition to local state variable m from
% bogvars.m
MW = y(1);
MB = y(2);
hs = y(3);
w = y(4);
S = y(5);
% Unpacking the parameters from bogvars.m
[alpha, beta, H1, H2, L, CV, deltaP, Bc, Kc, taus, Ga, taua, xia]=p{:};
% Retriving all the current value at time t using the function given
[QLi,CBLi,mdotBSi,hSP] = bogctrl(t);
% Algebraic equations
Mt = MW + MB; % eqn (14)
xBLo = MB/Mt; % eqn (11)
rhoLo = alpha + beta*(xBLo); % eqn (10)
hSPp = hSP/H1; % eqn (21)
htp = hs/H1; % eqn (20)
Vbot = 0.5*(H1+H2)*L^2; % eqn (16)
VT = Mt/rhoLo; % eqn (15)
mdotBLi = QLi*CBLi; % eqn (3)
sigma = hSPp - htp; % eqn (22)
Vtop = VT - Vbot; % eqn (17)
QLo = CV*S*(deltaP/rhoLo)^(0.5); % eqn (26)
mdotLo = rhoLo*QLo; % eqn (13)
xWLo = 1 - xBLo; % eqn (12)
syms mdotLi rhoLi xBLi positive
eq1 = (rhoLi*QLi)==mdotLi;
eq2 = alpha + beta*xBLi==rhoLi;
eq3 = xBLi*mdotLi==mdotBLi;
sol=solve(eq1,eq2,eq3,mdotLi,rhoLi,xBLi);
sol.mdotLi
sol.rhoLi
sol.xBLi
double(sol.mdotLi)
double(sol.rhoLi)
double(sol.xBLi)
Oc = Bc + Kc*sigma; % eqn (23)
h = H1-H2+(Vtop/L^2); % eqn (18)
mdotBLo = xBLo*mdotLo; % eqn (9)
mdotWLo = xWLo*mdotLo; % eqn (8)
mdotWLi = mdotLi - mdotBLi; % eqn (7)
% Evaluate the derivative of dMw/dt
dMWdt = mdotWLi-mdotWLo; % eqn (1)
dMBdt = mdotBLi + mdotBSi - mdotBLo; % eqn (2)
dhsdt = (h-hs)/taus; % eqn (19)
dwdt = ((Ga*Oc-S)/taua^2)-(2*(xia/taua)*w); % eqn (24)
dSdt = w; % eqn (25)
dmdt = [dMWdt dMBdt dhsdt dwdt dSdt]';
end
the errors are here
Error using odearguments (line 110)
Inputs must be floats, namely single or double.
Error in ode15s (line 148)
[neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...
Error in bogvars (line 34)
[t,y] = ode15s(@(t,y) mass(t,y,p), tspan, y0);
And the file which calculate the flow,
function [QLi,CBLi,mdotBSi,hSP] = bogctrl(t)
% BOGCTRL: Dynamic inlet conditions and level setpoint for solubilisation
% tank model
%
% Input variable:
% t Current time (s)
% Output variables:
% QLi Inlet liquor volumetric flowrate (m^3/s)
% CBLi Inlet boganite concentration in liquor (kg/m^3)
% mdotBSi Inlet mass flowrate of solid boganite (kg/s)
% hSP Level control set-point (m)
% Inlet liquor conditions remain fixed for the duration of the simulation
QLi = 0.0565;
CBLi = 43;
% Introduce step change in level set-point at t = 5 minutes
if t < 300
hSP = 2.5;
else
hSP = 2.2;
end
% Introduce step change in solids stream feed rate at t = 20 minutes
if t < 1200
mdotBSi = 21.5;
else
mdotBSi = 21.5*0.7;
end
Appreciate any help 🙂

Best Answer

The ode15s function does not accept symbolic values returned from your ode function. Use dsolve to solve the ODE symbolically or convert the symbolic values into double precision values before returning them from your ode function.