$29.99
Homework #2
There are two parts to this homework, both worth 50 points.
Use scipy.integrate.quad for both parts!
Part 1
Compute the value of the integral:
"
! (𝑎𝑥! + 𝑏𝑥 + 𝑐)𝑑𝑥 #
where r ranges from 0 to 5 in steps of 0.01, and a, b, and c are the constants 2, 3, and 4, respectively. Place the results on a plot using matplotlib. Then change the constants so that a, b, and c are 2, 1, and 1, respectively. Use these results to add another curve to your plot.
NOTE: You must use the same function for performing both integrals! That is, one function that computes the value of 𝑎𝑥! + 𝑏𝑥 + 𝑐. Therefore, you must pass the values of a, b, and c as arguments to the function!
To be clear, there will be two curves on your plot. Remember to properly label the axis and add a title. And don’t forget the legend!
Name your script hw2_poly.py.
Part 2
Compute the value of the integral:
$ 𝑑𝑥
!= 𝜋
# (1 + 𝑥)√𝑥
using the substituion method. (You might be able to find a package that will integrate this without substitution, but the point of this execise is to learn to do the substitution. Therefore, unless you do the substitution method, your work will not be counted!)
Note that this is a known integral whose answer is, in fact, 𝜋.
Print out your result to a precision of 8 digits past the decimal point. Then subtract your answer from numpy.pi and print the difference to 15 digits pas the decimal point.
NOTE: Be sure to use np.sqrt() to compute any square roots required.
Name your script hw2_pi.py.
Your output must match this format:
Pi is 3.14159265
Difference from numpy.pi is: -0.000000000000099