system of differential equations, function call
조회 수: 2 (최근 30일)
이전 댓글 표시
I have written the following code. Trying to simulate the zombie apocalypse. There might be something wrong with my ode45, and it might be something wrong with my function. I'd be grateful if someone could help me out :)
(I'm not quite sure about the 'options' either...)
%%%%%%%%%%%%%%%%%%%%%%%%%
syms x t;
tspan = [1 100];
options = odeset('RelTol',1e-6,'AbsTol',1,'InitialStep',tspan);
a = 1.4e-6;
b = 3.1e-8;
bd = 5.6e-16;
d = 2.8e-8;
i = 2.6e-6;
n = 1.4e-6;
r = 2.8e-7;
qi = 2.7e-6;
qz = 2.7e-6;
dq = 2.8e-5;
H0 = (b-d)/bd;
[t1,x1]=ode45(@(t,x) zombie1(t, x, a, b, bd, d, i, n, r),tspan,[H0,0,0,0]',options);
%%%%%%%ERROR MESSAGE%%%%%%%
zombie = 4×1
-0.0000
0
0
0.1500
Output argument "zombie1" (and maybe others) not assigned during call to "zombie1".
Error in MS_Ov3 (line 43)
[t1,x1]=ode45(@(t,x) zombie1(t, x, a,b,bd,d,i,n,r),tspan,[H0,0,0,0]',options);
Error in odearguments (line 90)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[t2,x2]=ode45(@(t,x) zombie2(t, x, a,b,bd,d,i,n,r,qi,qz,dq),tspan,[H0,0,0,0,0]',options);
figure(1)
subplot(1,2,1);
grid on;
plot(t1, x1, '-o');
title('Zombieapokalypse');
subplot(1,2,2);
grid on;
plot(t2, x2, '-o');
title('Zombieapokalypse m karantene');
%%%%%%%%%%%%%%%%%%%%%%%%
The code is written in matlab livescript, the functions are in different scripts, same path.
Here's the function: (Second one is similar)
%%%%%%%%%%%%%%%%
function zombie1 = zombie(t, x, a,b,bd,d,i,n,r)
zombie = [b*x(1) - d*x(1) - i*x(1)*x(3) - bd*x(1)^2;
i*x(1)*x(3) - a*x(2) - d*x(2);
a*x(2) - n*x(1)*x(3) + r*x(4);
d*(x(1) - x(2)) + n*x(1)*x(3) - r*x(4)]
end
댓글 수: 0
답변 (1개)
Star Strider
2021년 1월 28일
Try this:
function zombie1 = zombie(t, x, a,b,bd,d,i,n,r)
zombie1 = [b*x(1) - d*x(1) - i*x(1)*x(3) - bd*x(1)^2;
i*x(1)*x(3) - a*x(2) - d*x(2);
a*x(2) - n*x(1)*x(3) + r*x(4);
d*(x(1) - x(2)) + n*x(1)*x(3) - r*x(4)];
end
Also, there is no ‘zombie2’ function in the code you posted, and there are too many input arguments to ‘zombie’ in the second ode45 call. You need to fix those, as well as the problem with the odeset call.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!