필터 지우기
필터 지우기

ODE code is not working

조회 수: 2 (최근 30일)
Mr.DDWW
Mr.DDWW 2022년 4월 28일
답변: Star Strider 2022년 4월 28일
I tried to run the code but it is not working. here is the code
here is the code
clc;clf;clear all;close all;
syms X(t) Y(t) Z(t) YF alpha beta gamma1 gamma2 T theta
% The given data
YF=0.0667;
alpha= 0.29;
beta= 0.68;
gamma1=450;
gamma2=11.25;
theta=0.10895;
Ode1 = diff(X) == -X/theta + (1+alpha)*gamma1*(1-X)*Y^2 + beta*gamma1*(1-X)*Z^2;
Ode2 = diff(Y) == (YF-Y)/theta+(1-alpha)*gamma1*(1-X)*Y^2-gamma2*Y;
Ode3 = diff(Z) == -Z/theta+beta*gamma1*(1-X)*Z^2+2*alpha*gamma1*(1-X)*Y^2-(gamma2*Z)/beta;
Odes = [Ode1;Ode2; Ode3];
[VF, Subs] = OdeToVectorField ([Ode1, Ode2,Ode3]);
M = matlabFunction (VF, 'Vars',{'T','Y'});
% The given condtions
[t,y]=ode45(M, [0 5],[0.0667 0 0]);
figure
plot(t,y(:,1:2))
gride on
title('X and Y')
legend (string(subs))
[t,y]=ode45(M, [100 120],[0.0667 0 0]);
figure
plot(t,y(:,1:2))
gride on
title('X and Y')
legend (string(subs))
[t,y]=ode45(M, [100 120],[0.0667 0 0]);
figure
plot(t,y(:,1),t,y(:,2))
gride on
title('X vs Y')
legend (string(subs))

답변 (1개)

Star Strider
Star Strider 2022년 4월 28일
Problem:
[VF, Subs] = OdeToVectorField ([Ode1, Ode2,Ode3]);
Try this —
syms X(t) Y(t) Z(t) YF alpha beta gamma1 gamma2 T theta
% The given data
YF=0.0667;
alpha= 0.29;
beta= 0.68;
gamma1=450;
gamma2=11.25;
theta=0.10895;
Ode1 = diff(X) == -X/theta + (1+alpha)*gamma1*(1-X)*Y^2 + beta*gamma1*(1-X)*Z^2;
Ode2 = diff(Y) == (YF-Y)/theta+(1-alpha)*gamma1*(1-X)*Y^2-gamma2*Y;
Ode3 = diff(Z) == -Z/theta+beta*gamma1*(1-X)*Z^2+2*alpha*gamma1*(1-X)*Y^2-(gamma2*Z)/beta;
Odes = [Ode1;Ode2; Ode3];
[VF, Subs] = odeToVectorField ([Ode1, Ode2,Ode3]); % <— Corrected Misspelling
M = matlabFunction (VF, 'Vars',{'T','Y'});
% The given condtions
[t,y]=ode45(M, [0 5],[0.0667 0 0]);
figure
plot(t,y(:,1:2))
grid on
title('X and Y')
legend (string(Subs))
Warning: Ignoring extra legend entries.
[t,y]=ode45(M, [100 120],[0.0667 0 0]);
figure
plot(t,y(:,1:2))
grid on
title('X and Y')
legend (string(Subs))
Warning: Ignoring extra legend entries.
[t,y]=ode45(M, [100 120],[0.0667 0 0]);
figure
plot(t,y(:,1),t,y(:,2))
grid on
title('X vs Y')
legend (string(Subs))
Warning: Ignoring extra legend entries.
MATLAB is case-sensitive.
.

카테고리

Help CenterFile Exchange에서 Numerical Integration and Differential Equations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by