Contents

Before you turn this problem in, make sure everything runs as expected. First, restart the kernel (in the menubar, select Kernel\(\rightarrow\)Restart) and then run all cells (in the menubar, select Cell\(\rightarrow\)Run All).

Make sure you fill in any place that says YOUR CODE HERE or “YOUR ANSWER HERE”, as well as your name and collaborators below:

NAME = ""
COLLABORATORS = ""

Consider the function \(f(x) = e^{-x^2}\). Your task is to use Python to compute the definite integral of this function from x=0 to x=1.

Define the function: Write a Python function that represents the function.

Give one example that shows it works.

Plot the function: Use the matplotlib library to plot the function ( f(x) ) over the interval ([0, 1]). Make sure to label the axes.

Use the scipy.integrate.quad function from the SciPy library to compute the definite integral of \(f(x)\) over the interval ([0, 1]).

Use the trapezoid function from the numpy library to compute the definite integral of \(f(x)\) over the interval ([0, 1]). Compare your answer to the quad function. Discuss how you chose the number of points you used.


When you are done, download a PDF and turn it in on Canvas. Make sure to save your notebook, then run this cell and click on the download link.

%run ~/s25-06623/s25.py
%pdf