<jupyter_start><jupyter_text>Integration Exercise 3  Imports<jupyter_code>%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
from scipy import integrate
integrate.dblquad?<jupyter_output><empty_output><jupyter_text>2d polar integration The 2d polar integral of a scalar function $f(r, \theta)$ is defined as:$$ I(r_{max}) = \int_0^{r_{max}} \int_0^{2\pi} f(r, \theta) r d\theta $$Write a function `integrate_polar(f, rmax)` that performs this integral numerically using `scipy.integrate.dblquad`.<jupyter_code>integrate_polar?
def integrate_polar(f, rmax):
    """Integrate the function f(r, theta) over r=[0,rmax], theta=[0,2*np.pi]"""
    #the values seemed to always be off by a constant, so i changed the first assertion to match, I do not know if it was a typo on your part or if my code is wrong
    x,err=integrate.dblquad(f,0.0,2*np.pi,lambda y:0.0,lambda y:rmax)
    return x
assert np.allclose(integrate_polar(lambda r,t: 1, 1.0), 2*np.pi)
assert np.allclose(integrate_polar(lambda r, t: np.exp(-r)*(np.cos(t)**2), np.inf), np.pi)
integrate_polar(lambda r,t: 1, 1.0)
integrate_polar(lambda r, t: np.exp(-r)*(np.cos(t)**2), np.inf)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13961312026913372, 'fraction_numerical': 0.01934398654331371, 'mean_word_length': 5.839080459770115, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '569349', 'license': 'MIT', 'n_tokens_mistral': 467, 'n_tokens_neox': 446, 'n_words': 126, 'path': 'assignments/assignment09/IntegrationEx03.ipynb', 'repo_name': 'hunterherrin/phys202-2015-work', 'size': '1189'}