You are on page 1of 3

1.

Aim/Overview of the practical:


Write a program to implement Monte Carlo Simulation

2. Task to be done:
In this experiment we need to implement Monte Carlo Simulation.

3. Code for experiment/practical:


>> N = 10000;
>> a = -7;
>> b = 7;
>> r = 5;
>> x = a + (b-a).*rand(N,1);
>> y = a + (b-a).*rand(N,1);
>> radii = sqrt(x.^2+y.^2);
>> i = radii <= r;
>> hits = sum(i);
>> misses = N-hits;
>> plot(x(i),y(i),'.g');
>> hold;
>> plot(x(~i),y(~i),'.r');
>> ttl = sprintf('%d trails, %d hits, %d misses',N,hits,misses);
>> title(ttl);
>> plot(x(i),y(i),'.g','DisplayName',sprintf('%d hits',hits));
>> hold
>> plot(x(~i),y(~i),'.r','DisplayName',sprintf('%d misses',misses));
>> legend('show');

>> ttl = sprintf('%d trails, Area of the circle: %1.3f',N,hits/N*14^2);


>> title(ttl);

4. Result/Output/Writing Summary:
Summary:

Monte Carlo simulation is a method for exploring the sensitivity of a complex system by varying
parameters within statistical constraints. These systems can include financial, physical, and
mathematical models that are simulated in a loop, with statistical uncertainty between simulations. The
results from the simulation are analyzed to determine the characteristics of the system.

Learning outcomes (What I have learnt):


1. I have learnt how to use matlab online.
2. I have learnt what is monte carlo simulation.
3. I have learnt how to implement monte carlo simulation in matlab.
4. I have learnt importance of monte carlo simulation.
5. I have learnt uses of monte carlo simulation.

You might also like