Transcribed Text
1.1.1 Use scipy.integrate.romberg to evaluate the triple integral
∫ 1
x=0
∫
√
1−x
2
y=0
∫ √
1−x
2−y
2
z=0
dz dy dx
1 + x
2 + y
2 + z
2
Try to obtain results for a range of precision eg. tol=1e-3, 1e-4, ... See how small you can make
the tolerance and still obtain a result in under a minute or so. (It may be helpful to adjust divmax.)
Determine the number of calls N to the integrand
1
1 + x
2 + y
2 + z
2
required for each value of tol. Plot the graph of N versus tol and discuss the result.
1.1.2 A transformation from Cartesian to spherical coordinates changes the integral into the
following form
∫ π/2
θ=0
∫ π/2
ϕ=0
∫ 1
ρ=0
ρ
2
sin ϕ dρ dϕ dθ
1 + ρ
2
Apply the same methods as in the previous section to evaluate the triple integral in spherical
coordinates. Compare and discuss your results.
Use a Jupyter notebook with an .ipynb extension to write up this assignment and submit it
via D2L.
The name and UCID of each co-author must be included near the beginning.
Each notebook should have an introduction and conclusion/summary/discussion section.
Each graph must have a title, axis labels, and any other features required to make it easier to
understand eg. a legend.
Use graphs or tables instead of printing large blocks (ie. pages) of numbers.
Each non-trivial function should have a docstring.
Avoid duplication of code. Use functions and loops instead of cutting and pasting the same
lines in multiple places.
Describe what you did and explain why you did it. When you are writing your report, think
back to what you wish you had known when you started.
These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction
of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice.
Unethical use is strictly forbidden.
# Import python science module
import scipy
# Import integrate functions from python science module
from scipy import integrate
# Import python numerical module
import numpy as np
# Import python plotting module
import matplotlib.pyplot as plt
# Suppress warnings
import warnings
warnings.filterwarnings('ignore')
global_tol = 1e-4
global_n = 0
# Method to represent integrand function: f(x,y,z)
# This is the innermost function which will be integrated.
def integrand(z, y, x):
global global_n
global_n += 1
return 1/(1+x*x+y*y+z*z)
# Method to represent integral function with respect to z.
# This is the innermost integral function.
def integraldz(y, x):
if np.isnan(np.sqrt(1-x*x-y*y)):
return 0...