Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

image text in transcribed

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

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

Informix Database Administrators Survival Guide

Authors: Joe Lumbley

1st Edition

0131243144, 978-0131243149

More Books

Students also viewed these Databases questions

Question

Draw a schematic diagram of I.C. engines and name the parts.

Answered: 1 week ago