Error using odearguments (line 95) returns a vector of length 2, but the length of initial conditions vector is 3. The vector returned by function and the initial conditions vector must have the same number of elements.

29 views (last 30 days)
Dionisio Mendoza
Dionisio Mendoza on 2 Nov 2019
Commented: Walter Roberson on 3 Nov 2019
I am trying to make a couple of graphs with ODE functions, but it happens that I want to add 0.1 intervals to the graph from 0.001 to 1 but it shows the following error:
Error using odearguments (line 95)
CLASE2 returns a vector of length 2, but the length of initial conditions vector is 3. The vector returned by CLASE2 and
the initial conditions vector must have the same number of elements.
This is my function:
function dydt = clase2 (t,y)
Kso=0.153;
Kso1=0.135;
umax=0.253;
Kss=0.01;
Di=0.001;
Sen=2;
X=y(1); S=y(2);
u = (umax*X)/(Kss+S);
dXdt = (u*X)-(Di*X);
dSdt = ((-Kso*S*X)/(Kso1+S))-(Di*S)+(Di*Sen);
dydt = [dXdt dSdt]';
This is my script:
[t,x] = ode23('clase2',[0, 80],[0.001 0.01 1]);
plot(t,x(:,1));
xlabel('Tiempo (h)')
ylabel('Biomasa')
title('Biomasa')
figure
Di = 0.001;
plot(t,x(:,2));
xlabel('Tiempo (h)')
ylabel('Sustrato')
title('Sustrato')
  3 Comments
Walter Roberson
Walter Roberson on 3 Nov 2019
[t,x] = ode23('clase2',[0, 80],[0.001 0.01 1]);
Should be something like
y0 = vector of two values
tspan = [0, 0.001;0.01;1, 1:80];
[t, x] = ode23(@clase2, tspan, y0);

Sign in to comment.

Answers (1)

Steven Lord
Steven Lord on 2 Nov 2019
Are you trying to control the times at which ode23 returns the solutions of your ODEs to make them more finely spaced? If so, don't change the initial condition vector. Change the tspan input instead, specifying a vector with more than two elements. If you had called ode23 with one output instead of two, you could have used the deval function to evaluate that existing solution at a different set of times.
If you want to solve the system of ODEs at different values of Di, parameterize your ODE function. The examples on that page use fzero but the ode23 documentation page includes an example showing how to use one of those techniques with ode23.

Community Treasure Hunt

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

Start Hunting!

Translated by