## 源码简介

function globalExtinctionProb = metapop(tau)
%METAPOP A metapopulation simulation model
%   METAPOP(TAU) runs the metapopulation simulation described in the
%   November 2003 MATLAB News&Notes article, "Monte-Carlo simulation in
%   MATLAB using copulas".
%
%   Requires MATLAB?R13, including Statistics Toolbox?

% The metapopulation model will include 3 subpopulations, and weill run
% over 100 time steps (years).
npops = 3;
nyears = 100;

% In each time step, there's a 3% chance of extinction for each
% subpopulation, and a 25% chance that an active population will recolonize
% a locally extinct one.
probLocalExtinction = .03;
colonizationRate = .25;

% Compute the linear correlation parameter that will be needed for the
% Gaussian copula, as a function of the desired rank correlation in local
% extinctions.  By default, assume zero correlation.
if nargin == 0, tau = 0; end
if (tau < -1/3) || (1 < tau), error('TAU must be between -1/3 and 1.'); end
rho = sin(tau.*pi./2);

% Assume that the dependence in environmental variability between
% subpopulations is symmetric, i.e., equal correlations in local
% extinctions between all three pairs subpopulations.
R = [1 rho rho; rho 1 rho; rho rho 1];

% Run 10000 Monte-Carlo replicates in parallel.
nreplicates = 10000;

% Save a record of each subpopulation's presence/absence at each time step,
% for all the replicates.
presence = zeros(npops,nyears,nreplicates);
presence(:,1,:) = 1;
for yr = 2:nyears
% Local extinctions occur at a given site with probability
% probLocalExtinction, and are dependent between sites.  Model tht
% dependence with a Gaussian copula.
u = normcdf(mvnrnd([0 0 0], R, nreplicates));
u = reshape(u',[npops,1,nreplicates]);
localExtinction = (u < probLocalExtinction);

% A local population remains active if it was active last year,
% and it has not gone extinct this year.
presence(:,yr,:) = presence(:,yr-1,:) .* (1 - localExtinction);

% Count the number of local populations that are still active.
nActivePops = sum(presence(:,yr,:), 1);

% The probability that an extinct local population is recolonized
% depends on the number of other local populations that are still
% active.  Recolonizations are independent.
probColonization = repmat(1 - (1 - colonizationRate).^nActivePops, [npops,1,1]);
colonization = (rand(npops,1,nreplicates) < probColonization);

% An extinct local population becomes active again if it is colonized.
presence(:,yr,:) = presence(:,yr,:) + (1-presence(:,yr,:)).*colonization;
end

% The Monte-Carlo estimate of the probablility of global extinction is
% simply the number of replicates that went extinct diveide by the total
% number of replicates.
globalExtinctionProb = sum(all(presence(:,nyears,:) == 0, 1),3) ./ nreplicates

% Plot the subpopulation presence/absence for the first few replicates.
presence(presence==0) = NaN;
t = 1:nyears;
for i = 1:25
subplot(5,5,i)
plot(t,1.*presence(1,:,i),'r.', t,2.*presence(2,:,i),'b.', t,3.*presence(3,:,i),'m.');
end

## 本站长期招聘程序代写高手，欢迎加入华南地区matlab团队

 想创业却没有经验的人 无论你是否有过网上开店的经验，都可以随时联系在线客服，建立自己独立的网站 想开网店却不知道如何入手 淘宝创业成本低而且风险小，如果想开淘宝店的朋友可以联系在线客服。 想兼职创业，却不擅长交际与服务的人 在家创业月入5000元。网站程序+百套群发工具+网赚资料+域名+空间+本站终身代理资格，这样你网赚的条件全具备了。每天3小时管理、推广、收钱。 缺乏能快速赢利型产品的人 导入多种最新流行营销软件+网赚教程，让入驻者轻松加盟、复制有效成交技巧、快速赚钱。

## 源码评论评论内容只代表网友观点，与本站立场无关！

评论摘要(共 0 条，得分 0 分，平均 0 分) 查看完整评论

## 浏览说明

* 本站所有源码全部公开，随时随地浏览!
* MATLAB软件如用于商业用途，请购买正版!
* 如果您发现下载链接错误，请点击报告错误谢谢！
* 站内提供的所有软件包含破解及注册码均是由网上搜集，若侵犯了你的版权利益，敬请来信通知我们!