1

I am trying to solve this system of ODEs related to micro algae growth kinetics, I attach my function and script. I am getting some error related to the arguments. Please let me know where my error is thank you :) the system is composed of 7 ODEs and 7 corresponding state variables with 25 parameters

Function

function dx=odesys(t,var)
%dxdt=var(1);
%dldt=var(2);
%dsdt=var(3);
%dndt=var(4);
%gadt=var(5);
%Fadt=var(6);
%dhdt=var(7);
mumax=var(1);
Kxs=var(2);
Kixs=var(3);
Kxn=var(4);
Kixn=var(5);
qlmax=var(6);
Kls=var(7);
Kils=var(8);
Kinl=var(9);
Yxs=var(10);
Yxn=var(11);
Kh=var(12);
Yls=var(13);
Kxl=var(14);
Kixl=var(15);
Kli=var(16);
Kili=var(17);
sigma=var(18);
k1=var(19);
Kgas=var(20);
Kgan=var(21);
Kigan=var(22);
k2=var(23);
Kfas=var(24);
Kfan=var(25);
%Variable
%oilfree biomass--x(1)
%lipid production rate--x(2)
%Substrate consumption rate--x(3)
%N consumption rate--x(4)
%Byproduct GA--x(5)
%Byproduct FA--x(6)
%pH change--x(7)
%Rate equations 
S=2.01; %g/L
N=0.098; %g/L
X=0.001; %g/L
Io=125*10-6; %E/m^2*s
l=1;
Il=Io*exp(-sigma*X*l);
mux=mumax*(S/(S+Kxs+(S^2/Kixs)))*(N/(N+Kxn+(N^2/Kixn)))*(Il/(Il+Kxl+(Il^2/Kixl)));
mul=(qlmax)*(S/(S+Kls+(S^2/Kils)))*(Kinl/(N+Kinl)*(Il/(Il+Kli+(Il^2/Kili))));
%ODE
dx(1)=(mux*X);
dx(2)=(mul*X);
dx(3)=(-(1/Yxs)*dx(1))-((1/Yls)*dx(2));
dx(4)=(-(1/Yxn)*dx(1));
dx(5)=(k1*(S/(S+Kgas))*(N/(N+Kgan+(N^2/Kigan))));
dx(6)=(k2*(S/S+Kfas)*(N/N+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';
% dx=[dx(1);dx(2);dx(3);dx(4);dx(5);dx(6);dx(7)];
end 

Script

clear all
clc
%Time span to solve ODE
tspan=[0 120];
int=[0,0,0,0,0,0,0];
%Conditions 
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.519;2053.924;15.023;2152.918;34.104;0.329;1.456;12.976;2.533;1.4055;12.976;2.533];
V = odesys(tspan(1), var);
iscolumn(V) % false
isrow(V) % true?
%Using ODE 45 to solve system
[t,X]=ode45(@odesys,tspan,int,var);

Error functions

Error in odearguments (line 90)
f0 = feval(ode,t0,y0,args{:});   % ODE15I sets args{1} to yp0.
Error in ode45 (line 115)
  odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in run (line 17)
[t,X]=ode45(@odesys,tspan,int,var);
Lutz Lehmann
  • 25,219
  • 2
  • 22
  • 51
  • 1
    You need to use `odeset` to set any optional parameter like additional parameters of the ODE function `f(t,x,args)`. The `x` parameter needs to be present and be a state vector, so that `x+s*dx` is a valid ray in the state space. – Lutz Lehmann Jun 25 '20 at 08:28

1 Answers1

1

An easy way to do this is to define the 'var' variable inside your odesys function not in the script:

function dx=odesys(t, x)
%dxdt=var(1);
%dldt=var(2);
%dsdt=var(3);
%dndt=var(4);
%gadt=var(5);
%Fadt=var(6);
%dhdt=var(7);
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.519;2053.924;15.023;2152.918;34.104;0.329;1.456;12.976;2.533;1.4055;12.976;2.533];
mumax=var(1);
Kxs=var(2);
...

Note the changes in the function declaration. You have to add the x parameter here in function declaration. This is the variable which you are differentiating with respect to. You are not using it in your equations so you can name it anything but it should be included.

And finally, no need for the 'var' variable in the script as in here:

V = odesys(tspan(1));

and here:

[t,X]=ode45(@odesys,tspan,int);
Yahia Nagib
  • 91
  • 1
  • 3