where is the fault the code is not running as it has two delays with four variables?

1 visualización (últimos 30 días)
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 comentarios

Iniciar sesión para comentar.

Respuesta aceptada

Torsten
Torsten el 29 de Ag. de 2022
sol = exam4()
sol = struct with fields:
solver: 'dde23' history: [4×1 double] discont: [0 1 2 3 10 11 12 20 21 30] x: [0 0.0017 0.0100 0.0404 0.0799 0.1286 0.1870 0.2568 0.3408 0.4446 0.5812 0.7631 1 1.0705 1.1411 1.2412 1.3637 1.5238 1.7619 2 2.3612 2.6806 3 3.5036 4.1851 4.7974 5.4500 6.0327 6.5176 7.0104 7.5991 8.3186 9.1593 10 10.1250 10.2500 … ] y: [4×93 double] xe: [0.8619 2.1568 2.8145 3.9275 4.0992 4.4285 4.8781 5.0578 5.6089 5.6448 6.2286 6.2739 6.7236 6.9830 7.4267 7.4846 8.3411 8.3953 9.2627 9.2852 10.0491 11.1232 12.9423 13.3956 14.3223 15.1159 15.4958 15.6244 16.0784 16.1023 16.6493 16.6748 … ] ye: [4×95 double] ie: [3 1 2 3 4 1 3 2 1 4 3 2 1 4 3 2 4 1 2 3 1 3 4 3 1 2 1 4 2 3 1 4 3 2 1 4 3 2 1 4 3 2 4 1 3 2 1 3 1 4 2 3 1 4 3 2 1 4 3 2 1 4 3 2 1 4 2 3 1 3 2 4 2 3 4 1 3 2 1 3 2 1 4 2 3 1 4 3 2 1 4 3 2 1 4] stats: [1×1 struct] yp: [4×93 double]
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

Más respuestas (0)

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by