monte carlo integration in excel sean gant jay lee
TRANSCRIPT
Monte Carlo Integration in Excel
Sean Gant
Jay Lee
A
y
x
B
f(x)
Monte Carlo Integration
Monte Carlo Integration
A
y
x
B
f(x)
Monte Carlo Integration
A
y
x
B
f(x)
B
total
below
N
NABdxxf
0)(
Gas-phase elementary reaction:2A → B
Isothermal reaction in a PFR with no pressure drop
Only A is fed, P0 = 8.2 atm, T0 = 500K, ε = -0.5
CA0 = 0.2 mol/dm3, k = 10 dm3/mol-s, vo = 25 dm3/s
QUESTIONWhat volume is needed to achieve 90% conversion?
Mole Balance:
Rate Law:
Stoichiometry:
Combine:
X
AA r
dXFV
0
0
2AA kCr
)1(
)1(
0
0
Xv
XF
v
FC AAA
dXX
X
kC
FV
X
A
A
0 2
2
20
0
)1(
)5.01(
Setting Up Excel Spreadsheet
• What are your inputs? (Using “Rand()” Function)– X: Your independent variable (range you are
integrating)– Y: Dependent variable ( from 0 to max over X-
range)
• What is your defined area?– L x W of “box” (multiply the two ranges)
• What constitutes a hit?– If random point lies below function then “hit”
Setting up Excel Spreadsheet
Setting up Excel Spreadsheet• Random Number Generator
– Rand()*(b-a)+a • Generate a number between a and b
• The “Status”– If(X<f(X), “below”, “above”)
• If value of f(X) > Y then mark “below”
• The “Count”– If(Status=“below”,1,0)
• If value of status is “below” then count a “hit”
• Making sense of data– Take total number of hits and divide by total number of points to
find fraction under function– Multiply calculated fraction by area of “box” to find the area
under the curve. In this case this value is the volume of your PFR. 44.6 dm3 as compared to 45.3 dm3 found by solving analytically.
Setting up Excel Spreadsheet