I am trying to simulate a growth kinetics experience however I am constantly getting this error for my functions, any idea of how to solve it? I attached the function, script and error. Thank you!
function dx=odesys(t,x,var)
var[]
%Rate equations
l=0.001;
Io=125e-6;
Il=Io*exp(-sigma*x*l);
mux=mumax*(x(3)/(x(3)+Kxs+((x(3)).^2)/Kixs))*(x(4)/(x(4)+Kxn+((x(4)).^2)/Kixn))*(Il/(Il+Kxl+(Il.^2/Kixl)));
mul=qlmax*(x(3)/(x(3)+Kls+((x(3)).^2)/Kils))*(Kinl/(x(4)+Kinl)*(Il/(Il+Kli+(Il.^2/Kili))));
%ODE
dx(1)=mux.*x(1);
dx(2)=mul.*x(1);
dx(3)=(-(1/Yxs)*dx(1))-((1/Yls)*dx(2));
dx(4)=(-(1/Yxn)*dx(1));
dx(5)=(k1*(x(3)/(x(3)+Kgas))*(x(4)/(x(4)+Kgan+((x(4)).^2))/Kigan));
dx(6)=(k2*(x(3)/x(3)+Kfas)*(x(4)/x(4)+Kfan));
dx(7)=-Kh*(dx(3));
% The function return value is always a vector length equal to number of
% equations in model, and has to be a column vector
dx=dx';
end
Script:
clear all
clc
int=[0.001;0;2.1;0.098;0;0;7];
%Time span to solve ODE
tspan=[0 120];
options=[];
var=[0.227;0.050;9.923;0.065;0.5;0.121;6.554;0.110;380.023;1.47;6.883;0.879;0.064;19.519e-6;2053.924e-6;15.023e-6;2152.918e-6;34.104;0.329;1.456;12.976;2.533;1.4055;12.976;2.533];
%Using ODE 15 to solve system
[t,X]=ode15s(@odesys,tspan,int,options,var);
Errors:
Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.
Error in odesys (line 46)
dx(1)=mux.*x(1);
Error in odearguments (line 90)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode15s (line 150)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in script (line 14)
[t,X]=ode15s(@odesys,tspan,int,options,var);

 Respuesta aceptada

Star Strider
Star Strider el 26 de Jun. de 2020

1 voto

The problem is here:
Il=Io*exp(-sigma*x*l);
since ‘x’ (and therefore ‘Il’) is a (7x1) vector, and it creates the right-hand-side of ‘mux’ as:
0 0.0812 0 0 0 0 0
0 0.0812 0 0 0 0 0
0 0.0756 0 0 0 0 0
0 0.0809 0 0 0 0 0
0 0.0812 0 0 0 0 0
0 0.0812 0 0 0 0 0
0 0.0640 0 0 0 0 0
that is clearly not the scalar result you apparently want.
You need to decide on how you want to fix that.
.

6 comentarios

Carmen Escalante
Carmen Escalante el 26 de Jun. de 2020
How could I fix it? thank you
Star Strider
Star Strider el 26 de Jun. de 2020
As always, my pleasure!
How could I fix it?
I cannot determine that because I do not know what you want to do, or the system you are modeling. You need to decide what you want ‘Il’ to be. If you attach a PDF describing the system you want to simulate, I will see if I can determine how to fix it.
Carmen Escalante
Carmen Escalante el 26 de Jun. de 2020
Following the initial conditions and var constants that are given in the code this is the set of equations I am trying to model a system with 7 state variables and ODEs for the modelling of microalgael growth I am modelling an already existing paper to gain more knowledge on growth kinetics.
Star Strider
Star Strider el 26 de Jun. de 2020
The PDF solves the mystery!
The calculation for ‘Il’ should be:
Il=Io*exp(-sigma*x(1)*l);
since the reference to X in the PDF is actually ‘x(1)’ in your code. With that change, the code runs without error. The plots show what I would expect the reaction kinetics to look like.
Carmen Escalante
Carmen Escalante el 26 de Jun. de 2020
I just changed it and runs perfect thanks so much for your help!
Star Strider
Star Strider el 26 de Jun. de 2020
As always, my pleasure!

Iniciar sesión para comentar.

Más respuestas (0)

Preguntada:

el 26 de Jun. de 2020

Editada:

el 26 de Jun. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by