数模竞赛答题打卡第七天
主题活动
发布于 2025-08-26 15:54:30
查看 9过去306天
第一问
using TyMath
using TyPlot
function fun(t, y)
dy1=y[2]*y[3]
dy2=-y[1]y[3]
dy3=0.51y[1]*y[2]
return [dy1;dy2;dy3]
end
tspan = [0, 10]
y0=[0,1,1]
t,y,=ode45(fun,tspan,y0)
y1=y[:,1];y2=y[:,2];y3=y[:,3]
plot3(y1, y2, y3, "-o")
title("刚性体运动方程的数值解")
xlabel("y1")
ylabel("y2")
zlabel("y3")

第二问
using TyMath
using TyPlot
N=10000
β=0.4
γ=0.1
function sir_model(t,y)
s=y[1]
i=y[2]
r=y[3]
ds=-β*s*i/N
di=β*s*i/N-γ*i
dr=γ*i
return [ds;di;dr]
end
tspan=[0,100]
y0=[N-10,10,0]
t,y=ode45(sir_model,tspan,y0)
s=y[:,1]
i=y[:,2]
r=y[:,3]
plot(t,s,label="易感染人群(S)", linewidth=2)
hold("on")
plot(t,i,label="感染者(I)", linewidth=2)
hold("on")
plot(t,r,label="康复人群(R)", linewidth=2)
hold("on")
title("SIR模型预测(N=10000, β=0.4, γ=0.1)")
xlabel("Time (Days)")
ylabel("Population")
legend()
grid("on")

所属专栏:Julia语言
产品信息:Sysplorer系统建模仿真环境