Hello!
I am trying to find S from t= 0 to 10 but I couldn't manage to sort the code with the tutorials, S depends on X and I keep getting the error that I need an array of length 21 as an initial condition:
Equations:
ds/dt= D*(10-S)+rs
dx/dt= -D*X+um*X;
rs=-(ms*X+u*X/Y)
u=um*S/(k+S);
Code:
%Constants:
um=0.8; k=0.01; ms=0.05; Y=0.44; D=0.3; So=10;
t=0:0.5:10;
dxdt=@(t,X) -D*X+um*X;
[t,X]=ode45(dxdt, t, 1);
rs=-(ms*X+u*X/Y);
u=um*S/(k+S);
dsdt=@(t,S) D*(10-S)+rs;
[t,S]=ode45(dsdt, t, 10);

 채택된 답변

Star Strider
Star Strider 2019년 11월 9일

0 개 추천

I decided to let the Symbolic Math Toolbox have a go at your equations, since they involved some substitutions:
syms S(t) X(t) um k ms Yc D So Y t
u = um*S/(k+S);
rs = -(ms*X+u*X/Yc);
Eqns = [diff(S) == D*(10-S)+rs; diff(X) == -D*X+um*X];
[VF,Sbs] = odeToVectorField(Eqns)
odefcn = matlabFunction( VF, 'Vars',{t,Y, um,k,ms,Yc,D})
um=0.8; k=0.01; ms=0.05; Yc=0.44; D=0.3; So=10;
tspan=0:0.5:10;
ic = [10, So];
[T,Y] = ode45(@(t,Y)odefcn(t,Y,um,k,ms,Yc,D), tspan, ic);
figure
plot(T, Y)
grid
legend(string(Sbs), 'Location','S')
I included the constants as arguments, rather than hard-coding them in your equations. I also assume that ‘So’ is the initial condition for ‘S(t)’. In this code, ‘S(t)’ is the second column of ‘Y’.

댓글 수: 2

Zahra Ahmed
Zahra Ahmed 2019년 11월 9일
Thanks a lot!!
Star Strider
Star Strider 2019년 11월 9일
As always, my pleasure!

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

추가 답변 (0개)

카테고리

질문:

2019년 11월 9일

댓글:

2019년 11월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by