Write a program to implement Monte Carlo Simulation to calculate value of pi . to calculate value of pi In matlab
Answers
Answered by
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:
![](https://hi-static.z-dn.net/files/dc4/6d0c960e8f14a40a513954ad6ace7b30.jpg)
Similar questions