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.
|
| moran(initsize, popsize)
|
function [A1nmb] = moran(initsize, popsize)
% MORAN generates a trajectory of a Moran type process
% which gives the number of genes of allelic type A1 in a population
% of haploid individuals that can exist in either type A1 or type A2.
% The population size is popsize and the initial number of type A1
% individuals os initsize.
%
% [A1nmb] = galtonwatson(initsize, popsize)
%
% Inputs: initsize - initial number of A1 genes
% popsize - the total population size (preserved)
%
% Outputs: A1nmb - the successive number of type A1 genes in the population
% Authors: R.Gaigalas, I.Kaj
% v1.2 04-Oct-02
if (nargin==0)
initsize=10;
popsize=30;
end
A1nmb=zeros(1,popsize);
A1nmb(1)=initsize;
lambda = inline('(x-1).*(1-(x-1)./N)', 'x', 'N');
mu = inline('(x-1).*(1-(x-1)./N)', 'x', 'N');
x=initsize;
i=1;
while (x>1 & x<popsize+1)
if (lambda(x,popsize)/(lambda(x,popsize)+mu(x,popsize))>rand)
x=x+1;
A1nmb(i)=x;
else
x=x-1;
A1nmb(i)=x;
end;
i=i+1;
end;
nmbsteps=length(A1nmb);
rate = lambda(A1nmb(1:nmbsteps-1),popsize) ...
+mu(A1nmb(1:nmbsteps-1),popsize);
jumptimes=cumsum(-log(rand(1,nmbsteps-1))./rate);
jumptimes=[0 jumptimes];
stairs(jumptimes,A1nmb);
axis([0 jumptimes(nmbsteps) 0 popsize+1]);
|
|
Contact us at files@mathworks.com