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.

조회 수: 33 (최근 30일)
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
Dionisio Mendoza
Dionisio Mendoza 2019년 11월 2일
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
Walter Roberson 2019년 11월 3일
[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);

댓글을 달려면 로그인하십시오.

답변 (1개)

Steven Lord
Steven Lord 2019년 11월 2일
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.

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by