How to compute the mean of several stochastic realizations
I have a code that can be used to plot sample paths of the stochastic differential equation competition model
clear
a10=2; a20=1.5; a11=0.03;
a12=0.02; a21=0.01; a22=0.04;
x1(1)=50; x2(1)=25;
k=5000; T=5; dt=T/k;
num_realizations=10;
for j=1:num_realizations
for i=1:k
rn=randn(2,1);
f1=x1(i)*(a10-a11*x1(i)-a12*x2(i));
f2=x2(i)*(a20-a21*x1(i)-a22*x2(i));
g1=x1(i)*(a10+a11*x1(i)+a12*x2(i));
g2=x2(i)*(a20+a21*x1(i)+a22*x2(i));
x1(i+1)=x1(i)+f1*dt+sqrt(g1*dt)*rn(1);
x2(i+1)=x2(i)+f2*dt+sqrt(g2*dt)*rn(2);
x1p=[x1(i+1)>0];
x2p=[x2(i+1)>0];
x1(i+1)=x1(i+1)*x1p;
x2(i+1)=x2(i+1)*x2p;
end
plot([0:dt:T],x1,’Color’,rand(1,3),’LineWidth’,1);
hold on
plot([0:dt:T],x2,’Color’,rand(1,3),’LineWidth’,1);
ylabel(‘Population Size’); xlabel(‘Time’);
end
My question is how to plot the average of each population, including the initial conditions?I have a code that can be used to plot sample paths of the stochastic differential equation competition model
clear
a10=2; a20=1.5; a11=0.03;
a12=0.02; a21=0.01; a22=0.04;
x1(1)=50; x2(1)=25;
k=5000; T=5; dt=T/k;
num_realizations=10;
for j=1:num_realizations
for i=1:k
rn=randn(2,1);
f1=x1(i)*(a10-a11*x1(i)-a12*x2(i));
f2=x2(i)*(a20-a21*x1(i)-a22*x2(i));
g1=x1(i)*(a10+a11*x1(i)+a12*x2(i));
g2=x2(i)*(a20+a21*x1(i)+a22*x2(i));
x1(i+1)=x1(i)+f1*dt+sqrt(g1*dt)*rn(1);
x2(i+1)=x2(i)+f2*dt+sqrt(g2*dt)*rn(2);
x1p=[x1(i+1)>0];
x2p=[x2(i+1)>0];
x1(i+1)=x1(i+1)*x1p;
x2(i+1)=x2(i+1)*x2p;
end
plot([0:dt:T],x1,’Color’,rand(1,3),’LineWidth’,1);
hold on
plot([0:dt:T],x2,’Color’,rand(1,3),’LineWidth’,1);
ylabel(‘Population Size’); xlabel(‘Time’);
end
My question is how to plot the average of each population, including the initial conditions? I have a code that can be used to plot sample paths of the stochastic differential equation competition model
clear
a10=2; a20=1.5; a11=0.03;
a12=0.02; a21=0.01; a22=0.04;
x1(1)=50; x2(1)=25;
k=5000; T=5; dt=T/k;
num_realizations=10;
for j=1:num_realizations
for i=1:k
rn=randn(2,1);
f1=x1(i)*(a10-a11*x1(i)-a12*x2(i));
f2=x2(i)*(a20-a21*x1(i)-a22*x2(i));
g1=x1(i)*(a10+a11*x1(i)+a12*x2(i));
g2=x2(i)*(a20+a21*x1(i)+a22*x2(i));
x1(i+1)=x1(i)+f1*dt+sqrt(g1*dt)*rn(1);
x2(i+1)=x2(i)+f2*dt+sqrt(g2*dt)*rn(2);
x1p=[x1(i+1)>0];
x2p=[x2(i+1)>0];
x1(i+1)=x1(i+1)*x1p;
x2(i+1)=x2(i+1)*x2p;
end
plot([0:dt:T],x1,’Color’,rand(1,3),’LineWidth’,1);
hold on
plot([0:dt:T],x2,’Color’,rand(1,3),’LineWidth’,1);
ylabel(‘Population Size’); xlabel(‘Time’);
end
My question is how to plot the average of each population, including the initial conditions? the euler-maruyama method, sde models MATLAB Answers — New Questions