computer science
Homework 10
Suggested due date: November 16, 2021, Last day to turn in without penalty: November 21
For a Google Colab starter file, go to https://colab.research.google.com/drive/ 1U7k9ULhquJ_a80FRad0O7CjcFylgEyr-.
1. Compute an approximation for the average value of the function f(x) = 1 x+1
for x ∈ [0, 1] in the following way: let x = np.linspace(0, 1, 50). Then let f = 1/(x + 1). Use np.mean() to find the average of f.
2. Numerical approximation of integral
(a) Write code to appproximate the integral of the function 1 x+1
from x = 0 to x = 1 using rectangles.
(b) Compute ∫ 1 0
1 x+1
dx analytically and compare to your answer in part a.
3. Numerical approximation of a derivative
(a) Write code to approximate the derivative of f(x) = 1 x+1
in the following way: let h be a small number (for example, h = 0.1). Then by the definition of the
derivative, f ′(0) ≈ f(0+h)−f(0) h
. This gives the slope of the tangent.
(b) Find the actual derivative at 0; i.e. compute f ′(0) by calculus.
(c) Make a plot with the following two curves from parts a and b:
i. The function f(x) from x = 0 to x = 1.
ii. The line connecting (0, f(0)) and (h, f(h)) (the approximate tangent you computed in part a). Extend the line to go from x = 0 to x = 1. That is, plot the line connecting (0, f(0)) and (1, f(0) + f ′(0)).
1