This is a code that my team has been trying to fix but with no luck. There is one line on the graph that looks correct but the rest are all very small and wrong.

조회 수: 4 (최근 30일)
clear, clc, close all
load("EnvironmentalForcing.mat")
for i = 1:length(T)
if T(i)>0 && T(i)<35
Tb(i) = (0.000241*(T(i)^2.06737))*((35-T(i))^0.72859);
end
end
Bmax = 1;
uLi = sum(Tb);
uL = 1/uLi;
%uL = 6;
uI = 10;
E = 0.001;
Ap = 5000;
Pi = 930.27249;
Si = Pi/Ap;
Li = 0.01*Si;
Ii = 0;
Ri = uI*Ii;
Pbi = 0;
y0 = [Si,Li,Ii,Ri,Pi,Pbi];
ode = @(n,t,S,L,I,R,P,Pb) SLIRP(n, t, S, L, I, R, P, Pb, Bmax, uL, uI, E, T, Ap);
[t,y] = rk4(ode,tspan, y0);
y = y/Ap;
figure
hold on
plot(t,y(1,:),'k')
plot(t,y(2,:),'b')
plot(t,y(3,:),'g')
plot(t,y(4,:),'y')
plot(t,y(5,:),'m')
legend("S","L","I","R","P")
%% Functions
function [dsdt, dldt, dIdt, drdt, dpdt, dpbdt] = SLIRP(n, t, S, L, I, R, P, Pb, Bmax, uL, uI, E, T, Ap)
T = T(n);
d = t;
if T>0 && T<35
Tb = (0.000241*(T^2.06737))*(35-T)^0.72859;
B = Bmax * Tb;
else
B = 0;
end
TE = (-0.35968 + (0.10789*T) - (0.00214*(T^2)));
dpldt = 1.33*d*TE;
dpbdt = ((172.4*Pb) - (21.2*(Pb^2)))*TE;
dpdt = dpbdt + dpldt;
dsdt = (-B*S*I) + (dpdt*(1/Ap));
dldt = ((S*I) - (uL*L) + E);
dIdt = (uL*L) - (uI*I);
drdt = uI*I;
end
function [tp,yp] = rk4(f, tspan, y0)
q = length(y0);
N = length(tspan);
t0 = tspan(1);
h = tspan(2) - tspan(1);
tp = zeros(N+1,1);
yp = zeros(q, N+1);
tp(1) = t0;
yp(:,1) = y0;
for n=1:N
[k1(1), k1(2), k1(3), k1(4), k1(5), k1(6)] = f(n, tp(n), yp(1,n), yp(2,n), yp(3,n), yp(4,n), yp(5,n), yp(6,n));
[k2(1), k2(2), k2(3), k2(4), k2(5), k2(6)] = f(n, tp(n) + (0.5*h), yp(1,n) + (0.5*h*k1(1)), yp(2,n) + (0.5*h*k1(2)), yp(3,n) + (0.5*h*k1(3)), yp(4,n) + (0.5*h*k1(4)), yp(5,n) + (0.5*h*k1(5)), yp(6,n) + (0.5*h*k1(6)));
[k3(1), k3(2), k3(3), k3(4), k3(5), k3(6)] = f(n, tp(n) + (0.5*h), yp(1,n) + (0.5*h*k2(1)), yp(2,n) + (0.5*h*k2(2)), yp(3,n) + (0.5*h*k2(3)), yp(4,n) + (0.5*h*k2(4)), yp(5,n) + (0.5*h*k2(5)), yp(6,n) + (0.5*h*k2(6)));
[k4(1), k4(2), k4(3), k4(4), k4(5), k4(6)] = f(n, tp(n) + h, yp(1,n) + (h*k3(1)), yp(2,n) + (h*k3(2)), yp(3,n) + (h*k3(3)), yp(4,n) + (h*k3(4)), yp(5,n) + (h*k3(5)), yp(6,n) + (h*k3(6)));
for j = 1:q
fi(j) = (k1(j)/6)+(k2(j)/3)+(k3(j)/3)+(k4(j)/6);
yp(j,n+1) = yp(j,n) + h*fi(j);
end
tp(n+1) = tp(n) + h;
end
end

답변 (1개)

Image Analyst
Image Analyst 2023년 11월 27일
Yes, because the scale of the different plots is several orders of magnitude different so you can't see most of them if you use the same y scale. I suggest you plot them on separate axes, or use stackedplot
  댓글 수: 5
Image Analyst
Image Analyst 2023년 11월 28일
Well we have no idea where your formulas came from so you're going to have to research that yourself. Maybe some of the parameters are off by a few orders of magnitude, or were for different units (e.g. microns instead of meters).
This may help:
CONNOR
CONNOR 2023년 11월 28일
The formulas came from the assignment and same with the parameters. I dont think that those are wrong because I have checked them multiple times. Thanks for the video Ill check it out in hopes it can get me through this wall. Thanks for the help anyway.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by