Question
Thanks to anyone who can help me, this is a R program. Set a random seed (use set.seed() function). Use the Monte Carlo method (See
Thanks to anyone who can help me, this is a R program.
Set a random seed (use set.seed() function). Use the Monte Carlo method (See last page in lecture note 6) to calculate pi with the same accuracy as Problem 4. Compare the computational time of these two methods using system.time() or function. Compare the computational time of two methods. Bonus: adding one or more alternative ways for calculating pi will gain 3 bounus points to this homework.
Problem 4:
Write a while loop to calculate pi with accuracy 0.001 i.e. |yourestimatepi - pi|
Last page for Lecture 6 note:
Example: Calculate Pi (Monte Carlo method) Scatter Plot + + + > estpi = 0 > eps = 1 > incircle = 0 > total = 0 > start_time = Sys.time() > while(eps>0.001) { xvec = runif(100, min=-1, max=1) yvec = runif(100, min=-1, max=1) total = total + 100 incircle = incircle + sum((xvec^2 + yvec^2) end_time =Sys.time() > end_time-start_time Time difference of 0.1260011 secs T Ninner 4 Ntotal + + . + 30 10 05 10 Thirst 4 Ninner Ntotal Example: Calculate Pi (Monte Carlo method) Scatter Plot + + + > estpi = 0 > eps = 1 > incircle = 0 > total = 0 > start_time = Sys.time() > while(eps>0.001) { xvec = runif(100, min=-1, max=1) yvec = runif(100, min=-1, max=1) total = total + 100 incircle = incircle + sum((xvec^2 + yvec^2) end_time =Sys.time() > end_time-start_time Time difference of 0.1260011 secs T Ninner 4 Ntotal + + . + 30 10 05 10 Thirst 4 Ninner NtotalStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started