d y d t = a y 2 \cfrac{dy}{dt}=ay^2 dtdy=ay2
clc,clear
syms y(t) a %定义符号变量
dsolve(a*y^2-diff(y)==0)
结果
ans =
0
-1/(C1 + a*t)
d 3 y d t 3 = b y \cfrac{d^3y}{dt^3}=by dt3d3y=by
clc,clear
syms y(t) b %定义符号变量
dsolve(diff(y,3)-b*y==0)
结果
ans =
C3*exp(b^(1/3)*t) + C1*exp(-t*((3^(1/2)*b^(1/3)*1i)/2 + b^(1/3)/2)) + C2*exp(t*((3^(1/2)*b^(1/3)*1i)/2 - b^(1/3)/2))
x 2 + y + ( x − 2 y ) y ′ = 0 x^2+y+(x-2y)y\prime=0 x2+y+(x−2y)y′=0
clc,clear
syms y(x) %定义符号变量
dsolve(x^2+y+(x-2*y)*diff(y)==0)
结果:
ans =
x/2 + ((4*x^3)/3 + x^2 + C1)^(1/2)/2
x/2 - ((4*x^3)/3 + x^2 + C1)^(1/2)/2
d 2 y d t 2 = a y , 初 始 条 件 为 y ( 0 ) = 5 , y ′ ( 0 ) = 1 \cfrac{d^2y}{dt^2}=ay, \text初始条件为y(0)=5,y\prime(0)=1 dt2d2y=ay,初始条件为y(0)=5,y′(0)=1
clc,clear
syms y(t) a %定义符号变量
dy = diff(y);
y = dsolve(diff(y,2)==a*y,y(0)==5,dy(0)==1);
y = simplify(y) %化简结果
结果
y =
(exp(a^(1/2)*t)*(5*a^(1/2) + 1))/(2*a^(1/2)) + (exp(-a^(1/2)*t)*(5*a^(1/2) - 1))/(2*a^(1/2))
{ d y d t = z + 5 t d z d t = − 2 y \left\{\begin{aligned} \cfrac{dy}{dt}&=z+5t \\ \\ \cfrac{dz}{dt}&=-2y \\ \end{aligned}\right. ⎩⎪⎪⎪⎪⎪⎨⎪⎪⎪⎪⎪⎧dtdydtdz=z+5t=−2y
clc,clear
syms y(t) z(t) %定义符号变量
dy = diff(y);
dz = diff(z);
[y1,z1] = dsolve(dy==z+5*t,dz==-2*y);
y1 = simplify(y1) %化简结果
z1 = simplify(z1) %化简结果
结果:
y1 =
(2^(1/2)*C2*cos(2^(1/2)*t))/2 + (2^(1/2)*C1*sin(2^(1/2)*t))/2 + 5/2
z1 =
C1*cos(2^(1/2)*t) - 5*t - C2*sin(2^(1/2)*t)
clc,clear
yx = @(x,y) -2*y+2*x^2+2*x; %定义微分方程右端的匿名函数
[x,y] = ode45(yx,[0,0.5],1)
[x1,y1] = ode23(yx,[0,0.5],1)
plot(x,y,x1,y1)
根据以下提供的某省份年平均工资统计表(单位:元),通过马尔萨斯模型和阻滞增长模型构建微分方程,求解并绘制图像,应用两个模型分别计算并预测未来五年的工资走势.
x = [1978:1:2010]
y=[566,632,745,755,769,789,985,1110,1313,1428,1782,1920,2150,2292,2601,3149,4338,5145,5809,6271,6854,7656,8772,10007,11374,12567,14332,16614,19228,22844,26404,29638,32074]
模型假设:
模型建立和求解:
假设t时刻到 t + Δ t t+\Delta t t+Δt时间内工资的增量为:
{ d x d t = r x , x ( 0 ) = x 0 , \left\{\begin{aligned} \cfrac{dx}{dt}&=rx, \\ \\ x(0)&=x_0, \\ \end{aligned}\right. ⎩⎪⎪⎪⎨⎪⎪⎪⎧dtdxx(0)=rx,=x0,
其解为:
x ( t ) = x 0 ∗ e r t x(t)=x_0*e^{rt} x(t)=x0∗ert
对增长率r进行修正。如果在工资较少的时候,把r看成常数,工资增长到一定数量的时候,就应该把r看作应该随着工资增加而减少的量,即将增长率r表示成工资x(t)的函数r(x),r(x)是x的减函数。
模型假设:
模型求解:
由假设1、2, 可得 r ( x ) = r ( 1 − x x m r(x)=r(1-\cfrac{x}{x_m} r(x)=r(1−xmx), 则有
{ d x d t = r ( 1 − x x m ) x , x ( t 0 ) = x 0 , \left\{\begin{aligned} \cfrac{dx}{dt}&=r(1-\cfrac{x}{x_m})x, \\ \\ x(t_0)&=x_0, \\ \end{aligned}\right. ⎩⎪⎪⎪⎨⎪⎪⎪⎧dtdxx(t0)=r(1−xmx)x,=x0,
其解为:
x ( t ) = x m 1 + ( x m x 0 − 1 ) e − r ( t − t 0 ) x(t)=\cfrac{x_m}{1+(\cfrac{x_m}{x_0}-1)e^{-r(t-t_0)}} x(t)=1+(x0xm−1)e−r(t−t0)xm
x=[566 632 745 755 769 789 985 1110 ...
1313 1428 1782 1920 2150 2292 2601 3149 ...
4338 5145 5809 6271 6854 7656 8772 10007 ...
11374 12567 14332 16614 19228 22844 26404 29638 ...
32074]';
t=1978:2010;t=t';
t=t-1977;
near5year= [2011:1:2015]';
near5year=near5year-1977;
%阻滞增长增长模型
beta0 = [566 0.22 12567];
yzuzhi =@(beta,t) beta(3)./(1+(beta(3)./beta(1)-1).*exp(-beta(2)*t));
beta=nlinfit(t,x,yzuzhi,beta0)
xzuzhi=yzuzhi(beta,near5year);
%马尔萨斯增长模型
ymuthus=@(r,t) r(1)*exp(r(2)*t);
r0=[5.7,0.1];
a=nlinfit(t,x,ymuthus,r0)
xmuthus=ymuthus(a,near5year);
subplot(1,2,1);
plot([t;near5year],[x;xmuthus]);
title('马尔萨斯增长模型');
subplot(1,2,2);
plot([t;near5year],[x;xzuzhi]);
title('阻滞增长增长模型');
%预测未来五年
disp(['马尔萨斯增长模型预测未来五年工资是',num2str(xmuthus')]);
disp(['阻滞增长增长模型预测未来五年工资是',num2str(xzuzhi')]);
clear all;clc
x=[566 632 745 755 769 789 985 1110 ...
1313 1428 1782 1920 2150 2292 2601 3149 ...
4338 5145 5809 6271 6854 7656 8772 10007 ...
11374 12567 14332 16614 19228 22844 26404 29638 ...
32074]';
n = 33;
t = (1:n)';
beta0 = [5.3 0.22 400]; %[x0, r, xm]
[beta, R, J] = nlinfit(t,x,'logisfun',beta0); %非线性拟合
py = beta(3)./(1+(beta(3)./beta(1)-1).*exp(-beta(2)*t)); %预测各年工资
p5 = beta(3)./(1+(beta(3)./beta(1)-1).*exp(-beta(2)*(n:n+5)')); %预测五年后工资
subplot(2,1,1)
plot(1:n, x, '*', 1:n, py,n:n+5,p5,'o'); %对比图
title('阻滞增长增长模型');
xx = x(1:n);
t=[ones(n,1),(1:n)'];
y=log(xx(1:n));
[b,bint,r,rint,stats] = regress(y,t)
x0 = exp(b(1)) %参数x0
r = b(2)%参数r
py_ = x0*exp(r*(1:n+5)'); %预测数据
subplot(2,1,2)
plot(1:n, xx, 'k+', 1:n+5, py_); %对比图
title('马尔萨斯增长模型');
假设某一种传染病正在流行,现在希望建立适当的数学模型,利用已经掌握的一些数据资料对该传染病进行有效地研究,用于对其传播蔓延进行必要的控制,减少人民生命财产损失。现假设某地区人口分布约为5万人,且有约为5千人已经感染并积极治疗,每个病人每天接触约为5人,且每天治愈率约为150%。考虑如下问题,建立适当的数学模型:
病人治愈成为健康人,健康人可以再次被感染(SIS模型)
假设:
建模:
N [ i ( + Δ t ) − i ( t ) ] = λ s ( t ) N i ( t ) Δ t − μ N i ( t ) Δ t N[i(+\Delta t)-i(t)] = \lambda s(t)Ni(t)\Delta t -\mu Ni(t)\Delta t N[i(+Δt)−i(t)]=λs(t)Ni(t)Δt−μNi(t)Δt
得到:
{ d i d t = λ i s − u i i ( 0 ) = i 0 \left\{\begin{aligned} \cfrac{di}{dt}&=\lambda is-ui \\ \\ i(0)&=i_0\\ \end{aligned}\right. ⎩⎪⎪⎪⎨⎪⎪⎪⎧dtdii(0)=λis−ui=i0
clear all;
clc;
xspan = [0 5];
y0 = 0.1;
[x,y] = ode45(@(x,y) 5*y*(1-y)-1.5*y, xspan, y0);
y1 = 1-y(:)
plot(x,y,'r',x,y1,'b')
病人治愈后即移除感染系统,称为移出者(SIR模型)
假设:
建模:
s ( t ) + i ( t ) + r ( t ) = 1 s(t)+i(t)+r(t)=1 s(t)+i(t)+r(t)=1
需要建立 s ( t ) , i ( t ) , r ( t ) 的 两 个 方 程 s(t),i(t),r(t)的两个方程 s(t),i(t),r(t)的两个方程:
N [ i ( t + Δ t ) − i ( t ) ] = λ s ( t ) N i ( t ) Δ t − μ N i ( t ) Δ t N [ s ( t + Δ t ) − s ( t ) ] = − λ s ( t ) N i ( t ) Δ t N[i(t+\Delta t)-i(t)] = \lambda s(t)Ni(t)\Delta t -\mu Ni(t)\Delta t \\ \\ N[s(t+ \Delta t)-s(t)] =-\lambda s(t)Ni(t)\Delta t\\ N[i(t+Δt)−i(t)]=λs(t)Ni(t)Δt−μNi(t)ΔtN[s(t+Δt)−s(t)]=−λs(t)Ni(t)Δt
{ d i d t = λ i s − u i d s d t = − λ s i i ( 0 ) = i 0 , s ( 0 ) = s 0 \left\{\begin{aligned} \cfrac{di}{dt}&=\lambda is-ui\\ \cfrac{ds}{dt}&=-\lambda si \\ i(0)&=i_0,s(0)=s_0\\ \end{aligned}\right. ⎩⎪⎪⎪⎪⎪⎨⎪⎪⎪⎪⎪⎧dtdidtdsi(0)=λis−ui=−λsi=i0,s(0)=s0
无法求出s(t),i(t)的解析解,利用matlab求出数值解
function y = infect(t,x)
lamp = 5;
u = 1.5;
y = [lamp*x(1)*x(2)-u*x(1); -lamp*x(1)*x(2)];
end
x0 = [0.9, 0.1]';
[t,x] = ode45('infect', [0,4], x0);
%调用变步长4阶5级Runge-Kutta-Felhberg法计算
y = 1-x(:,1)-x(:,2)
plot(t,x(:,1),'r', t,x(:,2),'b',t,y,'k');
grid on