ODE45 error running odearguments

Function:
function dx=odesys(t,var)
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];
%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];
%Using ODE 45 to solve system
[t,X]=ode45(@odesys,tspan,var);
I get the following error can someone please help
Error using odearguments (line 93)
ODESYS must return a column vector.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in run (line 11)
[t,X]=ode45(@odesys,tspan,var);

Risposte (1)

Does your odesys function return a column vector, a row vector, or a non-vector?
If it returns a row vector (as I believe it does, and which you can check by calling odesys with the first element of tspan and the initial condition vector) have it return the transpose of that vector instead.
V = odesys(tspan(1), var);
iscolumn(V) % false
isrow(V) % true?

3 Commenti

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);
It still returned this errors any ide how to fix it??
Thank you
What is the full text of the error, everything displayed in red? What you've posted is missing the first bit of the error.
Thats all the error displayed,
I have been able to fix those erros however my graphs are not right.
I attach the function and script after changing it in case there is another error I am missing, thank you.
Function
function dx=odesys(t,X,var)
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*10^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];
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);
%Rate equations
S=1.5735; %g/L
N=0.0735; %g/L
X=0.001; %g/L
l=1;
Io=125*10-6; %E/m^2*s
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';
end
Script
clear all
clc
%Time span to solve ODE
tspan=[0:0.5:200];
int=[0,0,0,0,0,0,0];
%Using ODE 45 to solve system
[t,X]=ode45(@odesys,tspan,int);
figure(1)
subplot(3,3,1)
plot(t,X(:,1))
xlabel('time [h]')
ylabel('Biomass')
hold off
subplot(3,3,2)
plot(t,X(:,2))
xlabel('time [h]')
ylabel('Lipid')
subplot(3,3,3)
plot(t,X(:,3))
xlabel('time [h]')
ylabel('Nitrogen')
subplot(3,3,4)
plot( t,X(:,4))
xlabel('time [h]')
ylabel('pH')
subplot(3,3,5)
plot( t,X(:,5))
xlabel('time [h]')
ylabel('Acetate')
subplot(3,3,6)
plot( t,X(:,6))
xlabel('time [h]')
ylabel('Glycolic acid')
subplot(3,3,7)
plot( t,X(:,7))
xlabel('time [h]')
ylabel('Formic acid')

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by