Monte Carlo Integration in Excel Sean Gant Jay Lee Monte Carlo Integration y A f(x) x B Monte Carlo Integration y A f(x) x B Monte Carlo Integration y A f(x) x B B 0 N below f ( x)dx AB N total 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 QUESTION What volume is needed to achieve 90% conversion? X Mole Balance: Rate Law: dX V FA0 rA 0 rA kCA 2 Stoichiometry: FA FA0 (1 X ) CA v v0 (1 X ) Combine: FA0 V 2 kCA0 X 0 (1 0.5 X ) dX 2 (1 X ) 2 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 Xrange) • 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