Advertisement

02.05.2008 at 09:04AM PST, ID: 23138593 | Points: 500
[x]
Attachment Details

MATLAB Probability question

In this problem you will use a series of identical experiments, simulated in MATLAB, to estimate the value of pi. A dart board with diameter of 1/2 is centered within a square-board with sides of unity length. A series of N identical experiments are performed. The procedure consists of throwing a dart at the square-board, and the observation is determining if the dart falls on or off the dart board. The experiment model requires that the dart always lands within the square-board, and that the dart is equally likely to hit any specific point within the square-board. Let Ni denote the number of times the dart lands within the dart board for N experiments.
1. Estimate pi as a function of N and Ni, and denote your estimate as theta.
2. The MATLAB command x = rand( [N,1]) generates a column vector of N numbers, where each number lies in the interval [0, 1], and each value in this range is equally likely to occur. Using this function, find and plot theta as a function of N for 2 <= N <= 106.
Start your free trial to view this solution
Question Stats
Zone: Programming
Question Asked By: ncp118
Question Asked On: 02.05.2008
Participating Experts: 2
Points: 500
Views: 0
Translate:
Loading Advertisement...
02.05.2008 at 09:11AM PST, ID: 20824757

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
02.06.2008 at 06:26AM PST, ID: 20832126

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
07.09.2008 at 08:55AM PDT, ID: 21965118

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
Microsoft
  • Internet Protocols
  • Applications
  • Development
  • OS
  • Hardware
  • Windows Security
Apple
  • Operating Systems
  • Hardware
  • Programming
  • Networking
  • Software
Internet
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Spy / Ad Blockers
  • Web Browsers
  • New Net Users
  • Web Development
  • Chat / IM
  • Anti Spam
  • Web Servers
  • Anti-Virus
  • Email Clients
Gamers
  • Tips
  • Online / MMORPG
  • Puzzle
  • Emulators
  • Action / Adventure
  • Role Playing
  • Consoles
  • Game Programming
  • Strategy
  • Sports
  • Misc
  • Computer Games
Digital Living
  • Hardware
  • Automotive
  • New Net Users
  • New Users
  • Software
  • Digital Music
  • Gaming World
  • Home Security
  • Apple
  • Networking Hardware
Virus & Spyware
  • Vulnerabilities
  • IDS
  • Encryption
  • Anti-Virus
  • Operating Systems Security
  • Software Firewalls
  • WebApplications
  • Cell Phones
  • Operating Systems
  • Internet
  • Hardware Firewalls
Hardware
  • Displays / Monitors
  • Handhelds / PDAs
  • Components
  • Peripherals
  • Laptops/Notebooks
  • Servers
  • Misc
  • Apple
  • Embedded Hardware
  • Networking Hardware
  • Storage
  • Desktops
  • New Users
Software
  • System Utilities
  • Industry Specific
  • Network Management
  • Photos / Graphics
  • Page Layout
  • VMware
  • Misc
  • Web Development
  • OS
  • CYGWIN
  • Voice Recognition
  • Virtualization
  • Message Queue
  • Quality Assurance
  • Security
  • Firewalls
  • MultiMedia Applications
  • Development
  • Database
  • Office / Productivity
  • Business Management
  • OS/2 Apps
  • Server Software
  • Internet / Email
ITPro
  • OS
  • Storage
  • Encryption
  • Operating Systems Security
  • Apple Hardware
  • Laptops & Notebooks
  • Servers
  • Networking Hardware
  • Peripherals
  • Devices
  • Displays / Monitors
  • WebTrends / Stats
  • Search Engines
  • Firewalls
  • Web Computing
  • WebApplications
  • IDS
  • Vulnerabilities
  • Email Clients
  • File Sharing
  • Spy / Ad Blockers
  • Web Browsers
  • Web Servers
  • Networking
  • Anti-Virus
  • Consulting
  • Chat / IM
  • Anti Spam
Developer
  • Web Servers
  • Web Browsers
  • Game Programming
  • Dev Tools
  • Industry Specific
  • Office / Productivity
  • Database
  • CYGWIN
  • Web Development
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Programming
  • Content Management
  • Application Servers
  • Protocols
Storage
  • Removable Backup Media
  • Storage Technology
  • Servers
  • Grid
  • Remote Access
  • Backup / Restore
  • Misc
  • Hard Drives
OS
  • Miscellaneous
  • Security
  • Development
  • Linux
  • VMware
  • MainFrame OS
  • Unix
  • Apple
  • OS / 2
  • AS / 400
  • BeOS
  • Microsoft
  • VMS / OpenVMS
Database
  • Oracle
  • Miscellaneous
  • MySQL
  • Software
  • Sybase
  • Contact Management
  • PostgreSQL
  • Data Manipulation
  • Clarion
  • InterSystems Cache
  • Siebel
  • MUMPS
  • OLAP
  • SQLBase
  • SAS
  • GIS & GPS
  • 4GL
  • Berkeley DB
  • DB2
  • Informix
  • Interbase / Firebird
  • FoxPro
  • Reporting
  • LDAP
  • Filemaker Pro
  • MS SQL Server
  • dBase
  • MS Access
Security
  • Misc
  • Web Browsers
  • Software Firewalls
  • Operating Systems Security
  • File Sharing
  • Spy / Ad Blockers
  • Vulnerabilities
  • WebApplications
  • IDS
  • Anti-Virus
  • Encryption
  • Anti Spam
  • Email Clients
  • VPN
  • Chat / IM
Programming
  • Editors IDEs
  • Installation
  • Handhelds / PDAs
  • Multimedia Programming
  • System / Kernel
  • Automation
  • Algorithms
  • Game
  • Signal Processing
  • Project Management
  • Open Source
  • Database
  • Misc
  • Languages
  • Processor Platforms
  • Theory
Web Development
  • Scripting
  • Blogs
  • Web Servers
  • Software
  • Search Engines
  • Web Graphics
  • Web Services
  • Images
  • Internet Marketing
  • Images and Photos
  • Components
  • Document Imaging
  • Web Languages/Standards
  • Illustration
  • WebApplications
  • Fonts
  • WebTrends / Stats
  • Authoring
  • Digital Camera Software
  • Miscellaneous
Networking
  • Protocols
  • Apple Networking
  • Network Management
  • Message Queue
  • Application Servers
  • Content Management
  • File Servers
  • Email Servers
  • Misc
  • Java Editors & IDEs
  • Wireless
  • Networking Hardware
  • Backup / Restore
  • System Utilities
  • ISPs & Hosting
  • Web Servers
  • Storage Technology
  • Removable Backup Media
  • Servers
  • Web Computing
  • Broadband
  • Grid
  • OS / 2
  • Novell Netware
  • Unix Networking
  • Windows Networking
  • Security
  • Telecommunications
  • Operating Systems
  • Linux Networking
Other
  • Lounge
  • Business Travel
  • Community Support
  • New Net Users
  • Philosophy / Religion
  • Math / Science
  • Miscellaneous
  • URLs
  • Expert Lounge
  • Politics
  • Puzzles / Riddles
  • Automotive
Community Support
  • Suggestions
  • New to EE
  • New Topics
  • CleanUp
  • Announcements
  • General
  • Feedback
  • Input
  • EE Bugs
 
02.05.2008 at 09:11AM PST, ID: 20824757
This happens to be a problem for my 400 level probability class. I'm not used to using MATLAB and i've spent a lot of time just staring at this thing tryin to figure out what to do. Right about now, i'll take anything that remotely looks like a plot described by this problem. Any help would be fantastic right about now.

Thanks.
 
02.06.2008 at 06:26AM PST, ID: 20832126
You're probably overthinking it.

The dart has an equal probability of landing anyplace on the square board. You know when the dart lands on the circle. The probability of the dart landing on the circle is proportional to its area.

Number of darts on circle / total thrown = Area of circle = pi * r ^2. Solve for pi.
 
07.09.2008 at 08:55AM PDT, ID: 21965118
This problem is solved using monte carlo simulations. I guess you probably wanted this answer a while back, but since I only joined today, better late than never. ;-)

==========
Part 1.
==========

Area of circle = pi * r^2
Area of square = (2r)^2

Area circle / Area square = pi / 4

theta = Prob(dart hits circle) is directly proportional to (Area circle / Area square)

theta = num darts in circle / num darts in square
         = Ni / N  
        ~= (approximates) pi / 4

==========
Part 2.
==========

See code snippet. This should do the trick.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
clear all
close all
clc
 
% run Monte Carlo sim several times, for N darts
for N = 1 : 106
    
    % generate random x,y coords simulating dart hitting square board at a
    % random location
    x = rand([N,1]);
    y = rand([N,1]);
    
    % reset counter for num darts hitting dartboard
    in_circle = 0;
    
    % work out whether each simulated dart hit the dartboard
    for Ni = 1 : N
        % test if x,y coordinates are within circle w radius 0.5 
        % (subtract 0.5 from each coord to compare against circle 
        % centered on origin)
        if sqrt((x(Ni)-0.5).^2 + (y(Ni)-0.5).^2) <= 0.5
            in_circle = in_circle + 1;
        end
    end
   
    % calculate theta, our estimate for Pi
    theta(N) = 4 * in_circle / N;
    
    % write out theta values - should approach 3.14...
    disp(['N = ' num2str(N) ', in_circle = ' num2str(in_circle) ...
        ', theta = ' num2str(theta(N)) ])
 
end
 
% plot thesta values
figure;plot(theta)
Open in New Window
 
 
20080716-EE-VQP-33 / EE_QW_2_20070628