필터 지우기
필터 지우기

Please explain this code about differential equations.

조회 수: 2 (최근 30일)
Mr.DDWW
Mr.DDWW 2022년 5월 7일
답변: Sam Chak 2022년 5월 7일
Here is the matlab code
theta=0.10895;
YF=0.0667;
alpha= 0.29;
beta= 0.68;
gamma1=450;
gamma2=11.25;
X0=0; Y0=0.0667; Z0=0;
f=@(t,y)[-y(1)/theta+(1+alpha)*gamma1*(1-y(1))*y(2)^2+beta*gamma1*(1-y(1))*y(3)^2;...
(YF-y(2))/theta+(1-alpha)*gamma1*(1-y(1))*y(2)^2-gamma2*y(2);...
-y(3)/theta+beta*gamma1*(1-y(1))*y(3)^2+2*alpha*gamma1*(1-y(1))*y(2)^2-gamma2*y(3)/beta];
[T,Y]=ode45(f,[100 120],[X0,Y0,Z0]);
plot(T,Y(:,1),'-',T,Y(:,3),'-.',T,Y(:,3),'.');
Can you please tell me where the underlined numbers (below) come from in f=@(t,y) ??????????
-y(1)
(1-y(1))*y(2)
(1-y(1))*y(3)^2
(YF-y(2))
(1-y(1))*y(2)^2-gamma2*y(2)
-y(3)/theta+beta
(1-y(1))*y(3)^2+2
y(2)^2-gamma2*y(3)/beta

답변 (2개)

Star Strider
Star Strider 2022년 5월 7일
They refer to the function values returned by ode45 (in this code).
y(1) is X
y(2) is Y
y(3) is Z
That can easily be inferred by comparing the code to the symbolic differential equation system.

Sam Chak
Sam Chak 2022년 5월 7일
The code is annotated now. Hopefully sufficient for you to understand. By the way, I've fixed the plot line because you plotted Z(t) twice.
% Parameters
theta = 0.10895;
YF = 0.0667;
alpha = 0.29;
beta = 0.68;
gamma1 = 450;
gamma2 = 11.25;
% Initial values
X0 = 0;
Y0 = 0.0667;
Z0 = 0;
% A system of differential equations
f = @(t,y)[-y(1)/theta+(1+alpha)*gamma1*(1-y(1))*y(2)^2+beta*gamma1*(1-y(1))*y(3)^2;... % this is dX/dt
(YF-y(2))/theta+(1-alpha)*gamma1*(1-y(1))*y(2)^2-gamma2*y(2);... % this is dY/dt
-y(3)/theta+beta*gamma1*(1-y(1))*y(3)^2+2*alpha*gamma1*(1-y(1))*y(2)^2-gamma2*y(3)/beta]; % this is dZ/dt
% Solving the system f from time 100 s to 120 s with the initial values using the ode45 solver
[T, Y] = ode45(f, [100 120], [X0, Y0, Z0]);
% plotting the solutions for X(t), Y(t), Z(t)
plot(T, Y(:,1), '-', T, Y(:,2), '-.', T, Y(:,3), '.');
% additional stuff to display label, title, and legends
xlabel('Time, t [sec]')
title('Time responses of the System')
legend({'$X(t)$', '$Y(t)$', '$Z(t)$'}, 'Interpreter', 'latex', 'location', 'best')
Result:

카테고리

Help CenterFile Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by