<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Integration Exercise 2
Imports
Step1:  Indefinite integrals
Here is a table of definite integrals. Many of these integrals has a number of parameters $a$, $b$, etc.
Find five of these integrals and perform the following steps
Step2:  Integral 1
$$ I_1 =\int_0^a \sqrt{a^2-x^2}dx = \frac{\pi a^2}{4}$$
Step3:  Integral 2
$$ I_2 =\int_0^{2\pi} \frac{dx}{a+b\sin x} = \frac{2\pi}{\sqrt{a^2-b^2}} $$
Step4:  Integral 3
$$ I_3= \int_0^\infty e^{-ax}\cos{bx}dx = \frac{a}{a^2+b^2} $$
Step5:  Integral 4
$$ I_4 = \int_{-\infty}^\infty e^{-x^2}dx = \sqrt{\pi} $$
Step6:  Integral 5
$$ I_5 = \int_0^\infty e^{-ax^2}dx = \frac{1}{2}\sqrt{\frac{\pi}{a}} $$
<ASSISTANT_TASK:>
Python Code:
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
from scipy import integrate
Explanation: Integration Exercise 2
Imports
End of explanation
def integrand(x, a):
    return 1.0/(x**2 + a**2)
def integral_approx(a):
    # Use the args keyword argument to feed extra arguments to your integrand
    I, e = integrate.quad(integrand, 0, np.inf, args=(a,))
    return I
def integral_exact(a):
    return 0.5*np.pi/a
print("Numerical: ", integral_approx(1.0))
print("Exact    : ", integral_exact(1.0))
assert True # leave this cell to grade the above integral
Explanation: Indefinite integrals
Here is a table of definite integrals. Many of these integrals has a number of parameters $a$, $b$, etc.
Find five of these integrals and perform the following steps:
Typeset the integral using LateX in a Markdown cell.
Define an integrand function that computes the value of the integrand.
Define an integral_approx funciton that uses scipy.integrate.quad to peform the integral.
Define an integral_exact function that computes the exact value of the integral.
Call and print the return value of integral_approx and integral_exact for one set of parameters.
Here is an example to show what your solutions should look like:
Example
Here is the integral I am performing:
$$ I_1 = \int_0^\infty \frac{dx}{x^2 + a^2} = \frac{\pi}{2a} $$
End of explanation
def integrand(x,a):
    return np.sqrt(a**2-x**2)
def integral_approx(a):
    I,e=integrate.quad(integrand, 0,a,args=(a,))
    return I
def integral_exact(a):
    return np.pi*a**2/4
print("Numerical: ", integral_approx(1.0))
print("Exact: ", integral_exact(1.0))
assert True # leave this cell to grade the above integral
Explanation: Integral 1
$$ I_1 =\int_0^a \sqrt{a^2-x^2}dx = \frac{\pi a^2}{4}$$
End of explanation
def integrand(x,a,b):
    return 1.0/(a+b*np.sin(x))
def integral_approx(a,b):
    I,e=integrate.quad(integrand,0,2*np.pi,args=(a,b))
    return I
def integral_exact(a,b):
    return 2*np.pi/(np.sqrt(a**2-b**2))
print("Numerical: ", integral_approx(2.0,1.0))
print("Exact: ", integral_exact(2.0, 1.0))
assert True # leave this cell to grade the above integral
Explanation: Integral 2
$$ I_2 =\int_0^{2\pi} \frac{dx}{a+b\sin x} = \frac{2\pi}{\sqrt{a^2-b^2}} $$
End of explanation
def integrand(x,a,b):
    return np.exp(-a*x)*np.cos(b*x)
def integral_approx(a,b):
    I,e = integrate.quad(integrand,0,np.inf,  args=(a,b))
    return I
def integral_exact(a,b):
    return a/(a**2+b**2)
print("Numerical: ", integral_approx(1.0,1.0))
print("Exact: ", integral_exact(1.0,1.0))
assert True # leave this cell to grade the above integral
Explanation: Integral 3
$$ I_3= \int_0^\infty e^{-ax}\cos{bx}dx = \frac{a}{a^2+b^2} $$
End of explanation
def integrand(x):
    return np.exp(-x**2)
def integral_approx(x):
    I,e= integrate.quad(integrand,-1*np.inf,np.inf)
    return I
def integral_exact():
    return np.sqrt(np.pi)
print("Numerical: ", integral_approx(1.0))
print("Exact: ", integral_exact())
assert True # leave this cell to grade the above integral
Explanation: Integral 4
$$ I_4 = \int_{-\infty}^\infty e^{-x^2}dx = \sqrt{\pi} $$
End of explanation
def integrand(x,a):
    return np.exp(-a*x**2)
def integral_approx(a):
    I,e=integrate.quad(integrand, 0 , np.inf, args=(a,))
    return I
def integral_exact(a):
    return 0.5*np.sqrt(np.pi/a)
print("Numerical: ", integral_approx(2.0))
print("Exact: ", integral_exact(2.0))
assert True # leave this cell to grade the above integral
Explanation: Integral 5
$$ I_5 = \int_0^\infty e^{-ax^2}dx = \frac{1}{2}\sqrt{\frac{\pi}{a}} $$
End of explanation
<END_TASK>