{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lecture_24_s2005

# lecture_24_s2005 - 1.00 Lecture 24 Integration Reading for...

This preview shows pages 1–5. Sign up to view the full content.

1.00 Lecture 24 Integration Reading for next time: Numerical Recipes, pp. 347-368 (Get as far as you’re comfortable) Numerical Integration Classical methods are of historic interest only Rectangular, trapezoid, Simpson’s Work well for integrals that are very smooth or can be computed analytically anyway Extended Simpson’s method is only elementary method of some utility for 1-D integration Multidimensional integration is tough If region of integration is complex but function values are smooth, use Monte Carlo integration (first exercise) If region is simple but function is irregular, split integration into regions based on known sites of irregularity If region is complex and function is irregular, or if sites of function irregularity are unknown, give up We’ll cover 1-D extended Simpson’s method only See Numerical Recipes chapter 4 for more

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Monte Carlo Integration x y z=f(x,y) Integrate f(x,y) over Circular Area r 2r 2r Randomly generate points in square 4r 2 . Odds that they’re in the circle are π r 2 / 4r 2 , or π / 4. This is Monte Carlo integration, with f(x,y)= 1 If f(x,y) varies slowly, then evaluate f(x,y) at each sample point in limits of integration and sum (0,0)
Integration over Circular Area public class MonteCarloIntegration { public static double circularIntegral() { int nIter= 1000000; double sum= 0.0, radius= 0.5; for (int i=0; i < nIter; i++) { // Math.random() returns double d: 0 <= d <= 1 double x= Math.random() - radius; // Ctr at 0,0 double y= Math.random() - radius; double f= 1.0; // f(x,y)—constant here if ((x*x + y*y) < radius*radius) // If in region sum += f; // Increment integral sum } return sum/nIter; // Integral value } public static void main(String[] args) { System.out.println(“Result: “ +circularIntegral() ); System.out.println(“Pi: “+ 4.0*circularIntegral() ); } } Integration over Circular Area, 2 // To integrate f(x,y) = exp (x)/(y*y+1) over this area: public class MonteCarloIntegration2 { public static double circularIntegral() { // for loop, random x, y same as previous slide // … double f= Math.exp(x)/(y*y+1); if ((x*x + y*y) < radius*radius) // If in region sum += f; // Increment integral sum } return sum/nIter; // Integral value } public static void main(String[] args) { System.out.println(“Result: “ +circularIntegral() ); } } // Numerical integration is used when functions and areas // of integration are really complex and ugly!

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Exercises: Take Your Pick Find the shaded area within circles below: Use circularIntegral() as your starting point Use f(x,y)= 1 to find the areas below using integration Equation of circle is (x-x c ) 2 + (y-y c ) 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern