- Do you receive warning and/or error messages? If so the full and exact text of those messages (all the text displayed in orange and/or red in the Command Window) may be useful in determining what's going on and how to avoid the warning and/or error.
- Does it do something different than what you expected? If so, what did it do and what did you expect it to do?
- Did MATLAB crash? If so please send the crash log file (with a description of what you were running or doing in MATLAB when the crash occured) to Technical Support so we can investigate.
where is the fault the code is not running as it has two delays with four variables?
1 回表示 (過去 30 日間)
古いコメントを表示
function sol = exam4
options = ddeset('Events',@exam4e);
sol = dde23(@exam4f,[1, 10],[5; 0.1; 1],[0, 40],options);
xe = sol.xe;
ye = sol.ye;
ie = sol.ie;
n1 = find(ie == 1);
x1 = xe(n1);
y1 = ye(1,n1);
n2 = find(ie == 2);
x2 = xe(n2);
y2 = ye(2,n2);
n3 = find(ie == 3);
x3 = xe(n3);
y3 = ye(3,n3);
figure
plot(sol.x,sol.y,'k',x1,y1,'rs',x2,y2,'rs',x3,y3,'rs')
title('Infectious disease model from Hairer et alia.')
xlabel('Maxima are indicated by red squares.')
function yp = exam4f(x,y,Z)
ylag1 = Z(:,1);
ylag2 = Z(:,2);
k1 = 2;
k_1 = 1;
k2 = 1;
k3 = 1;
k_3 = 1;
k4 = 2;
k5 = 1;
k6 =1.5;
E1 = 1;
E2 = 2;
yp = [-k1*y(1)*E1+k_1*y(2)+k4*y(3);
k1*y(1)*E1-(k_1+k2)*y(2)-k5*ylag1(1);
k3*y(4)*E2-(k_3+k4)*y(3)-k6*ylag2(2);
k2*y(2)+k_3*y(3)-k3*y(4)*E2+k5*ylag1(1)+k6*ylag2(2)];
function [value,isterminal,direction] = exam4e(x,y,Z)
value = exam4f(x,y,Z,);
isterminal = zeros(3,1);
direction = -ones(3,1);
8 件のコメント
採用された回答
Torsten
2022 年 8 月 29 日
sol = exam4()
function sol = exam4
options = ddeset('Events',@exam4e);
sol = dde23(@exam4f,[1, 10],[5; 0.1; 1; 7],[0, 40],options);
xe = sol.xe;
ye = sol.ye;
ie = sol.ie;
n1 = find(ie == 1);
x1 = xe(n1);
y1 = ye(1,n1);
n2 = find(ie == 2);
x2 = xe(n2);
y2 = ye(2,n2);
n3 = find(ie == 3);
x3 = xe(n3);
y3 = ye(3,n3);
figure
plot(sol.x,sol.y,'k',x1,y1,'rs',x2,y2,'rs',x3,y3,'rs')
title('Infectious disease model from Hairer et alia.')
xlabel('Maxima are indicated by red squares.')
end
function yp = exam4f(x,y,Z)
ylag1 = Z(:,1);
ylag2 = Z(:,2);
k1 = 2;
k_1 = 1;
k2 = 1;
k3 = 1;
k_3 = 1;
k4 = 2;
k5 = 1;
k6 =1.5;
E1 = 1;
E2 = 2;
yp = [-k1*y(1)*E1+k_1*y(2)+k4*y(3);
k1*y(1)*E1-(k_1+k2)*y(2)-k5*ylag1(1);
k3*y(4)*E2-(k_3+k4)*y(3)-k6*ylag2(2);
k2*y(2)+k_3*y(3)-k3*y(4)*E2+k5*ylag1(1)+k6*ylag2(2)];
end
function [value,isterminal,direction] = exam4e(x,y,Z)
value = exam4f(x,y,Z);
isterminal = zeros(4,1);
direction = -ones(4,1);
end
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!