HW 4


  1. In the goat grazing problem a farmer has a circular pen, and at the bottom of the pen a goat is tethered to a post as shown on the left side of the figure below. The farmer wishes to figure out how long the rope should be (\(r\)) so that the goat has access to exactly half of the grass in the pen. We normalize the radii so that the pen has a radius of 1 (and thus \(r\) is actually the goat’s radius relative to the pen’s radius).

    First we need to figure out how much area is contained in the gray region. A little algebra, which I’ll skip for brevity, allows us to find the equation of the curve above the gray area and an equation below (these equations are shown in the right figure in blue and red respectively). We also find the \(x\) location of the intersections. Given a guess for \(r\) we can numerically integrate to determine the area of the gray region.

    Start with a fixed value of \(r\), say \(r = 1\) just to make sure your integral is working. But to fully solve the problem we need to determine \(r\) such that the area of the gray region is half of the upper circle (which has a radius of 1). We can’t explicitly solve for \(r\), and must add a root finder around the integral function to determine \(r\).

  2. Consider the function

    \[f(x) = e^x \sin x\]

    We will numerically evaluate the derivative at \(x = 1.5\) with forward finite differencing. Try the following step sizes: \(10^{-1}\), \(10^{-6}\), \(10^{-11}\), \(10^{-17}\). Print out the percent error for all four cases (the function is simple enough that we know the exact answer). Comment on what you observe.

  3. Use the same function as the last problem, but this time integrate from \(x = 0 \ldots 1\). Write your own trapezoidal integration function rather than using a built-in one. Make sure you use enough points to get at least 3 significant figures of accuracy.

  4. A remote control car has the following measured times (in seconds) and positions (in meters). Use numerical differentiation to estimate the vehicle’s velocity as a function of time. Plot the position and velocity, as a function of time, on the same plot. Add a legend and label the x-axis.

     time = np.array([0.0, 0.24489796, 0.44897959, 0.65306122, 0.85714286, 1.06122449, 1.26530612, 1.46938776, 1.67346939, 1.87755102, 2.08163265, 2.28571429, 2.48979592, 2.69387755, 2.89795918, 3.10204082, 3.30612245, 3.51020408, 3.71428571, 3.91836735, 4.12244898, 4.32653061, 4.53061224, 4.73469388, 4.93877551, 5.14285714, 5.34693878, 5.55102041, 5.75510204, 5.95918367, 6.16326531, 6.36734694, 6.57142857, 6.7755102 , 6.97959184, 7.18367347, 7.3877551 , 7.59183673, 7.79591837, 8.])
     position = np.array([0.16326531, 0.97959184, 1.79591837, 2.6122449,  3.42857143, 4.24489796, 5.06122449, 5.87755102, 6.69387755, 7.51020408, 8.32653061, 9.14285714, 9.95918367, 10.7755102, 11.59183673, 12.40816327, 13.2244898, 14.04081633, 14.85714286, 15.67346939, 16.46730529, 17.14618909, 17.70012495, 18.12911287, 18.43315285, 18.6122449, 18.666389, 18.59558517, 18.3998334, 18.07913369, 17.63348605, 17.06289046, 16.36734694, 15.54685548, 14.60141608, 13.53102874, 12.33569346, 11.01541025, 9.57017909, 8.])