Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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:

image text in transcribed

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 Ntotal

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Driven Web Sites

Authors: Mike Morrison, Joline Morrison

1st Edition

061901556X, 978-0619015565

More Books

Students also viewed these Databases questions

Question

i. What was the outcome of the interaction?

Answered: 1 week ago