返回信息流%% SIR模型仿真
function [residual, variance] = sir (a, b)
% ode45 is to solve initial value problems for ordinary differential
% equations. We can use different odefun to change the value of λ and μ
[t,x]=ode45('ill3',[0:01.0/24.0:15],[0.00001,0.99999], a, b); %
% initial data plot: weibo message number vs time
figure
plot(t, initialData),grid;
xlabel('时间/天')
ylabel('微博转发数/天')
T = 24*t;
xNihe = 1-x(:,2);
xNoise = xNihe+abs(0.05*randn(361,1));
figure
plot(t(1:10:361), xNoise(1:10:361)*1000000),grid;
xlabel('时间/天')
ylabel('微博转发数Noise/天')
hold on
plot(t, xNihe*1000000,'color','red')
% result plot: s vs t
figure
plot(t,x(:,2)*1000000),grid;
xlabel('时间t')
ylabel('健康者s')
% result plot: i vs t
figure
plot(t,x(:,1)*1000000),grid;
xlabel('时间t')
ylabel('传染者i')
% result plot: r vs t
figure
plot(t,(1-x(:,1)-x(:,2))*1000000),grid;
xlabel('时间t')
ylabel('免疫者r')
% result plot: weibo message number vs time
figure
plot(t, (1-x(:,2))*1000000),grid;
xlabel('时间/天')
ylabel('微博转发数/天')
hold on
% initial data plot: weibo message number vs time
plot(t, initialData)
%% residual and variance calculaton
residual = abs(initial-(1-x(:,2))*1000000);
variance = residual .* residual;
%% the SIR ode function
function y=ill(t,x,a, b)
%change a to change the value of λ
% change b to change the value of μ
y=[a*x(1)*x(2)-b*x(1),-a*x(1)*x(2)]';
%% calculate the proper value of μ: b(index) is the value
a = 4;
b = 1:0.01:4;
residual = zeros(1,length(b));
variance = zeros(1,length(b));
for kk = 1:length(b)
[residual(kk), variance(kk)] = sir (a, b(kk));
end
index = find(min(variance));
这是一条镜像帖。来源:北邮人论坛 / matlab / #10045同步于 2013/6/8
该镜像源已超过 30 天没有更新,可能在源站已被删除。
Matlab机器人发帖
急急急急!!!求大神帮忙看个matlab程序调试的时候出现的问题
yinyawen
2013/6/8镜像同步2 回复
订阅后,新回复会通过你的通知中心匿名送达。