Question: Class:- Numerical Analysis Program used: Matlab Write Matlab program to calculate Pi and plot darts with the targets as shown in the sample graph above.

Class:- Numerical Analysis

Program used: Matlab

Class:- Numerical Analysis Program used: Matlab Write Matlab program to calculate Pi

and plot darts with the targets as shown in the sample graph

Write Matlab program to calculate Pi and plot darts with the targets as shown in the sample graph above. Sample Matlab code for plotting is given below: axis([-1, 1,-1, 1] ); axis manual equal set(gca,'xTick',[-1 0 1]); set(gca,'yTick', [-1 0 1]); fill(x, y, [0.8, 0.8, 0.8]); %fill a polygon with color space (RGB) 0-1 plot(x, y, 'ko', 'MarkerEdgeColor','k','MarkerFaceColor','r', 'MarkerSize',5); %'ko' for black circles

Approximation of a a is a mathematical constant that is the ratio of any circle's circumfer-ence to its diameter. 7 is approximately equal to 3.14 in the usual deci-mal notation. Many formulas in mathematics, science, and engineering in-volve , which makes it one of the most important mathematical constants. (3.14159265...) is an irrational number, which means that its value cannot be expressed exactly as a fraction having integers in both the numerator and denominator. Consequently, its decimal representation never ends or repeats. (from wikipedia.com) The following describes a method of approximating the value of a by throwing darts. Suppose that a dart player throws a number of darts at a circular target inscribed into a square and all the darts land inside the square. Figure 1 shows an imaginary distribution of darts on the target. Assume that the chances to hit anywhere inside the square are equal. If a dart lands inside the circle, it is counted as a hit, otherwise a miss. It is observed that the chance (probability) to hit inside the circle is proportional to the ratio of the area of the circle to the area of the square. A mathematical formula is used to express the relationship: R2 i = (2R)2 = where H is the number of hits and T is the total number of darts thrown. Then it can be expressed as: T = 4 The steps to approximate the value of a: 1. Generate a pair of x and y coordinates of darts that marks the lo- cation of a dart hit on the target using a random number generator function called rand(1). It generate a decimal number between 0 and 1 (exclusive) Simulation of Pi Figure 1: Distribution of Darts on a Target 2. Calculate the distance between the darts and the origin of the coordi- nate system with the formula below: d=V x2 + y2 3. Assume that the radius R of the circle target is 1. If d is less than 1, count as a hit, otherwise a miss. 4. Count the number of hits and the total number of darts thrown. 5. Calculate y using the preceding formula a = 4

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!