# 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.

27 visualizaciones (últimos 30 días)
Dionisio Mendoza el 2 de Nov. de 2019
Comentada: Walter Roberson el 3 de Nov. de 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 comentariosMostrar 1 comentario más antiguoOcultar 1 comentario más antiguo
Dionisio Mendoza el 2 de Nov. de 2019
Thanks!
What I want to do is that in the two graphs I have already made there are 0.01 jumps that start at 0.001 and end at 1
Walter Roberson el 3 de Nov. de 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);

Iniciar sesión para comentar.

### Respuestas (1)

Steven Lord el 2 de Nov. de 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.
##### 1 comentarioMostrar -1 comentarios más antiguosOcultar -1 comentarios más antiguos
Dionisio Mendoza el 3 de Nov. de 2019
I can not understand, i need to put another ecuation?

Iniciar sesión para comentar.

### Categorías

Más información sobre Programming en Help Center y File Exchange.

### Community Treasure Hunt

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

Start Hunting!

Translated by