Matlab Programming - PowerPoint PPT Presentation

1 / 13
About This Presentation
Title:

Matlab Programming

Description:

We have a bag containing 50 golf balls. They are all white, except for one blue ball. ... ball at a time and remove it from the bag, what is the expected number ... – PowerPoint PPT presentation

Number of Views:27
Avg rating:3.0/5.0
Slides: 14
Provided by: derek113
Category:

less

Transcript and Presenter's Notes

Title: Matlab Programming


1
Matlab Programming
Statistical Simulations
2
Monte Carlo Method
a statistical simulation that relies on the
probabilities involved with the repeated use of
random numbers
3
A Monte Carlo Method Scenario
Flipping a Coin
4
A Simple Probability Problem
We have a bag containing 50 golf balls. They are
all white, except for one blue ball. If we
randomly select one ball at a time and remove it
from the bag, what is the expected number of
balls that we need to select to get the blue ball?
5
Code For One Trial
let the blue ball be represented by a 1
generated by randperm number_of_balls
50 ballPicks randperm(number_of_balls)
counter 1 while ballPicks(counter) 1
counter counter1 end
6
Complete Code
let the blue ball be represented by a 1
generated by randperm number_of_balls
50 trials 1000 for i 1trials
ballPicks randperm(number_of_balls)
counter 1 while ballPicks(counter) 1
counter counter1 end
trialResults(i) counter end aveNumPicks
mean(trialResults)
7
Results of Code
Trials
Average Number of Picks
1000
25.2720
Results should converge to 25.5
25.4638
5000
25.5192
10,000
50,000
25.5466
100,000
25.4893
8
Monte Carlo Integration
y 1/2
9
Monte Carlo Integration
Integral (Percentage of Points Below line y
1/2)(Area of Range of Random Points)
10
Problem
Use Monte Carlo Integration to solve
p
ò
sin(x) dx
0
11
p
ò
sin(x) dx
0
y
1
Random Point Range 0 x p 0 y 1
x
p
12
Monte Carlo Integration Code
numTrials 1000 counter 0 for i
1numTrials random_x pirand(1)
random_y rand(1) if random_y lt
sin(random_x) counter counter 1
end end proportion of random points under
curve proportion counter/numTrials area of
range of possible random points area
pi1 solution proportionarea
13
Results of Code
Trials
Solution
1000
2.0138
Solution should converge to 2
2.0339
5000
2.0053
10,000
50,000
1.9830
100,000
1.9945
1,000,000
2.0013
Write a Comment
User Comments (0)
About PowerShow.com