$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