Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PLEASE HELP ME WRITE THE CODE IN C LANGUAGE. PLEASE EXPLAIN. THANKS. Intro to C- Lab Assignment 1 Approximating Pi Monte Carlo Method The law

PLEASE HELP ME WRITE THE CODE IN "C LANGUAGE". PLEASE EXPLAIN. THANKS.

image text in transcribed

Intro to C- Lab Assignment 1 Approximating Pi Monte Carlo Method The law of large numbers" states that the more random trials we run, the closer to the expected/true outcome we can expect. For example, if we wanted to know how often the sides of a die land, we can roll the die again and again and keep count of how many times each side comes up. In the short run, we may see long streaks of certain values, but in the long run we will see each side come up approximately 1/6th of the time. Monte Carlo methods are a class of algorithm that uses randomness to approximate a value using this law, if we have a uniform distribution levenly spread out) set of random trials, we can simulate the outcomes and average them to predict the expected value in reality. For example, the US Coast Guard uses software that looks at a large number of simulated paths for vessels to determine where to look for search and rescue operations. Monte Carlo Method for Pi If we have a circle in a square, where the radius of the circle 1, and side length of the square is 2 (so that the circle fits perfectly inside it ).ts the area of the circle isR, and the area of the square is 4. This means CS if you picked a random point in the square, it would be inside the circe R times out of 4. Alternatively, we can think of this as saying "SOS that if we pick N random points in the square and want to know how many points were the circle (well call it M), M = N in Rearranging this, we get 4M To simplify our code, we can do this just using one corner of the shape. This divides the area of the circle ind the square by 4, which cancels outleaving the math unchanged. Generating Random Doubles The rand() function generates a random number between and RANDMAXcan use 0 the constant , we this range to generate a random double double X rand()RAND _ux; O) / (double Remember that we have to cast one part of it to a double, otherwise it will treat them as integers and round it down to 0. What to turn in Your assignment is to write code that approximates don't expect it to be incredibly close the value of pi e this method, and displays the approximated value. Please submit the code that you created for this, in the usual format. The typical late work, namine and honor code policies apply

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

Filing And Computer Database Projects

Authors: Jeffrey Stewart

2nd Edition

007822781X, 9780078227813

Students also viewed these Databases questions

Question

Explain the factors affecting dividend policy in detail.

Answered: 1 week ago

Question

Explain walter's model of dividend policy.

Answered: 1 week ago

Question

What about leadership lessons from particularly good or bad bosses?

Answered: 1 week ago

Question

How would you assess the value of an approach like this?

Answered: 1 week ago

Question

When would you use one approach, and when would you use another?

Answered: 1 week ago