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

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 :)

4 commentaires

The // tells us that you are not using MATLAB. You might be using Octave. On the other hand, Octave does not support symbolic expressions, so it is a mystery as to which language you are using.
Hi, I'm using Matlab. I just accidentally typed that \\ on the top. Sorry for that :(
Eddy Tan:
This is not a private programming service. The volunteers answers questions here under the condition that the question and answer remain public for everyone to learn from. If your code was confidential you should never have posted it: you should have hired a consultant. If your code was not confidential, you should restore it to the posting.
Rain flagged,
"Edited out due to copyright reason. But the problem and solutions remain in the thread. Please closed this thread."

Connectez-vous pour commenter.

 Réponse acceptée

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.

7 commentaires

Hi, Thanks for the answer.
May I know which part of my variables are symbolic?
Well, you directly defined some as symbolic:
syms mdotLi rhoLi xBLi positive
Then you defined other variables by performing operations on those variables, and some of those variables are also symbolic.
You can use symbolic variables and perform symbolic calculations inside your ode function, so long as your ode function returns only double or single precision results rather than symbolic results.
So, that's mean, all those equation related to [syms mdotLi rhoLi xBLi] have to change to double type right?
As I thought in my code below can change them back to double variable type :(
double(sol.mdotLi)
double(sol.rhoLi)
double(sol.xBLi)
So is there any other way that I can run my code without changing the code below?
[t,y] = ode15s(@(t,y) mass(t,y,p), tspan, y0);
The ode15s function doesn't really care what you do inside your mass function. It cares about what the mass function returns and that return value must be double or single precision. So you can perform your internal calculations using symbolic variables, but the value you return must be converted into double or single precision before mass returns it to ode15s.
Ok. So what you mean is, the value that I passed to ode15s must be double or single right?
In my cases, it's these right?
dMdt = [dMWdt dMBdt dhsdt dwdt dSdt]';
So, before ODE15s, i had to add a few line of codes that is used to convert my value into double or single precision right?
If yes, how?
Sorry, I'm really new in Matlab and really need help :(
Hi,
EDIT: -tried putting double(dMdt) at the end of the function mass.m (still having the same error)
Yes, the dMdt variable that mass returns to ode15s must be double or single. At the very end of mass, just before it returns, try adding this line:
dMdt = double(dMdt);
The command "double(dMdt);" alone won't do it; you need to assign the converted value back into the variable for the variable to change.
Hi. Thanks alot. Finally it runs. Really appreciate your help :)

Connectez-vous pour commenter.

Plus de réponses (1)

Rain, there has to be really extraordinary reasons for us to close a Question that has suitable Answers. For example, we did delete one case where someone was asking for answers to the exam they were in the middle of writing.
Every piece of code that is "sufficiently novel" is automatically copyrighted by the author (at least in any country which is a signature to the Berne Convention on Copyright), so we do not close questions just because they contain copyrighted code. Especially since most countries have "fair use" / "fair dealings" exemptions for "analysis and critique", which certainly was being done here.
If the material was Confidential or Trade Secret, then, in law, it lost that status as soon as it was posted in public. It may have been deleted here, but there are an unknown number of copies of it on the 'net. It should be presumed that it escaped.
We very much discourage people deleting postings after they have been answered. This is a free service where the Questions are answered by volunteers who give their efforts as a public service. What we "charge" for it is that the discussion is public. If there are confidentiality concerns then there are people who can be hired. The discussion and effort was not a gift to you alone: it was a gift to everyone.

Catégories

En savoir plus sur Symbolic Math Toolbox dans Centre d'aide et File Exchange

Tags

Question posée :

le 7 Mai 2016

Rouvert :

le 27 Juil 2016

Community Treasure Hunt

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

Start Hunting!

Translated by