Code covered by the BSD License
-
birthdeath(npoints, flambda, ...
BIRTHDEATH generate a trajectory of a birth-death process
-
bm3plot(npoints, sigma)
% BM3PLOT Generate and plot a 3-dimensional Brownian motion
-
brownian(npoints, sigma)
BROWNIAN generate and plot an aproximation to Brownian motion.
-
galtonwatson(nmbgen, initsize...
GALTONWATSON generates a trajectory of a Galton-Watson branching process
-
moran(initsize, popsize)
MORAN generates a trajectory of a Moran type process
-
poisson2d(lambda)
POISSON2D generate and plot Poisson process in the plane
-
poisson3d(lambda)
POISSON3D generate and plot Poisson process in the unit cube
-
poissonjp(njumps, lambda, ntr...
POISSONJP generate and plot a number of trajectories of a Poisson
-
poissonti(tmax, lambda, nproc...
POISSONTI generate N independent Poisson processes as matrix
-
ranwalk(npoints, p)
RANWALK generate and plot a trajectory of a random walk which
-
ranwalk2d(npoints, p)
-
ranwalk3d(npoints, p)
-
rw3plot(npoints, ntrajs, p)
RW3PLOT generate and plot some trajectories of the process
-
View all files
from
Simulation of Stochastic Processes
by Ingemar Kaj Raimundas Gaigalas
Simulates and plots trajectories of simple stochastic processes.
|
| galtonwatson(nmbgen, initsize, p)
|
function [popsize] = galtonwatson(nmbgen, initsize, p)
% GALTONWATSON generates a trajectory of a Galton-Watson branching process
% with offspring distribution p=(p0, p1,...,pn), starting with initsize
% individuals at time 0.
%
% [popsize] = galtonwatson(nmbgen, initsize, p)
%
% Inputs: nmbgen - number of generations
% initsize - initial size of the population
% p - vector of offspring probabilities (p0, ..., pn). They should
% sum up to 1.
%
% Outputs: popsize - the successive size of the population
% Authors: R.Gaigalas, I.Kaj
% v1.2 04-Oct-02
if (nargin==0)
nmbgen=100;
initsize=40;
p=[1/2 0 1/2];
end
% check arguments
if (sum(p) ~= 1)
error('Probabilities does not sum up to 1');
end
% p=[0.3 0.4 0.2 0.1]; % Examples of offspring probabilitites
% p=[1/2 0 1/2];
popsize=zeros(1,nmbgen);
popsize(1)=initsize;
k=1;
while k<=nmbgen
popsize(k+1)=offspring(popsize(k),p);
k=k+1;
end
stairs((0:nmbgen),popsize)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function nu=offspring(k,p)
z=[cumsum(p)];
n=length(p); % nmb of possible offspring
offmu=dot(0:n-1,p); % offspring mean
u1=sort(rand(1,k));
for j=1:n
u(j)=length(find(u1<z(j)));
end
u=diff([0 u]);
nu=u*(0:n-1)';
|
|
Contact us at files@mathworks.com