Repeat simulation 300 times and plot all simulations in one graph
Show older comments
Hello
I've created a simulation, which I want to repeat 300 times, and the plot all the 300 simulations of the series in one graph. This is my code so far:
%script
X=rvdk;
a=9.5; %estimate value for a
b=0.4; %estimate value for b
c=0; %estimate value for c
d=159.7; %estimate value for d
T=257; %number of iterations (equals the number of observations in X)
lambda=montecarlo(X,a,b,c,d,T);
My function montecarlo looks like this:
function lambda=montecarlo(X,a,b,c,d,T)
i=1:T;
y0=1;
lambda0=0;
X0=0.0044;
lambda(1)=a+b.*y0+c.*lambda0+d.*X0;
for i=1:T;
y(i)=poissrnd(lambda(i));
lambda(i+1)=a+b.*y(i)+c.*lambda(i)+d.*X(i);
end
Now I want to carry out the montecarlo function 300 times resulting in 300 series of 257 observations (since X has 257 observations) and then I want to plot all these series in the same graph. How is this done? I've tried using nested loops, but that hasn't gotten me nowhere.
I look forward to hear from you
Accepted Answer
More Answers (1)
Prashant Arora
on 13 May 2020
0 votes
lambda = zeros(300,257);
figure; hAxes = gca;
hold( hAxes, 'on' )
for i = 1:300
lambda(i,:) = montecarlo(X,a,b,c,d,T);
plot( hAxes, lambda(i,:) );
end
Categories
Find more on Animation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!