Patrick Forrester Section 101
Homework 7: Numerical Differentiation, Integration, Monte Carlo
** Submit this notebook to bCourses to receive a credit for this assignment. **
Please complete this homework assignment in code cells in the iPython notebook. Include comments in your code when necessary. Enter your name in the cell at the top of the notebook, and rename the notebook [email_name]_HW07.ipynb, where [email_name] is the part of your UCB email address that precedes "@berkeley.edu"
Problem 1: Numerical integration [Ayars 2.2]
Compare results of the trapezoid integration method, Simpson’s method, and the adaptive Gaussian quadrature method for the following integrals:
For each part, try it with more and with fewer slices to determine how many slices are required to give an ‘acceptable’ answer. (If you double the number of slices and still get the same answer, then try half as many, etc.) Parts (3) and (4) are particularly interesting in this regard. In your submitted work, describe roughly how many points were required, and explain.
Problem 2: Numerical differentiation [Ayars 2.8]
Write a function that, given a list of abscissa values and function values , returns a list of values of the second derivative of the function. Test your function by giving it a list of known function values for and making a graph of the differences between the output of the function and . Compare your output to Python's scipy.misc.derivative
Problem 3: MC integration [similar to Ayars 6.1]
Find the volume of the intersection of a sphere and an infinite cylinder, using Monte Carlo techniques. The sphere has radius 1 and is centered at the origin. The cylinder has radius 1, its axis is parallel to the axis, and and goes through the point . Report your uncertainty.
Problem 4: MC integration [similar to Ayars 6.2]
The “volume” of a 2-sphere (a.k.a. a “circle”) is . The volume of a 3-sphere is . The equation for an N-sphere is (where are spatial coordinates in dimensions). We can guess, by induction from the 2-dimensional and 3-dimensional cases, that the “volume” of an N-sphere is . Write a function that uses Monte Carlo integration to estimate and its uncertainty for a fixed . Graph with its uncertainty as a function of for .