Numerical Analysis I

MATH 345 : Fall 2023

Department of Mathematics - SUNY Geneseo
⇐ Back

Homework 2 - Bisection Method

Due Date: September 19, 2023

Upload

Report all answers to 8 decimal places. If you are asked to prove a statement and you use a theorem from class then state what the theorem is.

Problems

  1. Use the bisection method to find an approximation $p^*$ to the zero $p$ of the function $f(x) = -2x^3-4x^2+4x +4$ on the interval $[-3,-2]$ such that $|p-p^*| < 0.1$. Show all your steps on how you arrived at $p^*$ and what the intervals $[a_n,b_n]$ are. How many iterations of the Bisection method were necessary and what is $f(p^*)$? (In this question, you are not asked to use Python to implement the Bisection method but rather to implement the method by hand and calculator.)
  2. The growth of a certain population can be modeled via the function \[ P(t) = P_0 e^{\alpha t} + \frac{\mu}{\alpha}(e^{\alpha t} -1 ) \] where $P(t)$ is the size of the population at time $t$, $P_0$ is the initial size of the population, $\alpha$ is the birth rate of the population, and $\mu$ is the rate of immigration. Suppose that $P(0) = 1,000,000$, $P(1) = 1,564,000$, and $\mu=435,000$. Use your Python bisection method to find an approximation $\alpha^*$ to the birth rate $\alpha$ such that $|\alpha-\alpha^*|<1\times 10^{-5}$. Once you find $\alpha^*$, use it to compute the value $P(1)$ and compare it to 1564000.
  3. Let $f(x) = \arctan(x)$ and $g(x) = \cos(x)$. Use your Python bisection method to find an approximation $p^*$ to the point $p$ where the graphs of $f$ and $g$ intersect. Find $p^*$ so that $|p-p^*|<1\times 10^{-12}$.
  4. Let $f(x) = 10\cosh(x/4) - x$ for $x\in [-1,2]$.
    1. Use the matplotlib module to plot $f$ on the interval $[-1,2]$. Label the $x$-axis of your plot and give it a title. Print and include your plot in your submission. (Hint: See the Python code below on how to make a basic plot.)
    2. From your plot, notice that $f$ has a minimum in the interval $[-1,2]$. Use your Python bisection method to find an approximation $p^*$ to the minimum point $p$ of $f$ in $[-1,2]$.
    Hint: $\cosh(x)$ and $\sinh(x)$ are the hyperbolic cosine and sine function, respectively, and the numpy module has built-in functions to evaluate $\cosh$ and $\sinh$.
    import numpy as np
    import matplotlib.pyplot as plt
    
    #%% Basic plot
    N = 200
    t = np.linspace(-2 * np.pi, 2 * np.pi, N)
    y = np.sin(t)
    
    plt.plot(t, y)
    plt.xlabel('time (s)')
    plt.ylabel('voltage (mV)')
    plt.title('Sine function')
    plt.grid(True)
    plt.savefig("sin_plot.pdf")
    #plt.show()
    
    #%% Two plots together
    x1 = np.linspace(0.0, 5.0)
    x2 = np.linspace(0.0, 2.0)
    
    y1 = np.cos(2 * np.pi * x1) * np.exp(-x1)
    y2 = np.cos(2 * np.pi * x2)
    
    plt.subplot(2, 1, 1)
    plt.plot(x1, y1, 'ko-')
    plt.title('Two plots')
    plt.ylabel('Damped oscillation')
    
    plt.subplot(2, 1, 2)
    plt.plot(x2, y2, 'r.-')
    plt.xlabel('time (s)')
    plt.ylabel('Undamped')
    
    #%% Something interesting: Floating-point precision
    
    x = 0.1
    y = 0.2
    z = 0.3
    
    x + y == z
    
    print('0.1 = {:.17f}'.format(x))
    print('0.2 = {:.17f}'.format(y))
    print('0.3 = {:.17f}'.format(z))
    print('0.1 + 0.2 = {:.17f}'.format(x+y))
    
    np.round(x + y, decimals=8) == np.round(z, decimals=8)
    
  5. Let $f(x) = x^2 - 1 + \arctan(x)$ for $x\in [-1,1]$.
    1. Prove that $f$ has a zero in the interval $[-1,1]$.
    2. Find $K>0$ such that $|f(x)-f(y)|\leq K |x-y|$ for all $x,y\in [-1,1]$, and thus proving that $f$ is Lipschitz. (Hint: Use theorems from class.)
    3. Based on your $K$, analytically find $n$ such that $|f(p_n)|< \varepsilon$, where $p_n$ is the $n$th term of the sequence generated by the Bisection method on the interval $[-1,1]$.
    4. For $\varepsilon = 1\times 10^{-12}$, use your Python bisection method to find $p_n$ such that $|f(p_n)|<\varepsilon$.