Computer Science, asked by cu17BCS2904, 7 months ago

Write a program to implement Monte Carlo Simulation to calculate value of pi . to calculate value of pi In matlab

Answers

Answered by sahilabhi
1

Answer:

Code for experiment/practical:

inside=0;

nmax=10000

for n=1:nmax

   x=rand;

   y=rand;

   if sqrt(x^2+y^2)<=1

       plot(x,y,'g.');

       inside=inside+1;

   else

       plot(x,y,'r.');

   end

   hold on;

end

hold off;

mypi=4*inside/nmax;

fprintf('%8.4f/n',mypi);

Attachments:
Similar questions