Lecture 45: Fourth Review ========================= The question on the fourth review focus on 1. function definitions, differentiation, integration; 2. plotting in two and three dimensions; 3. solving linear, differential, polynomial equations, linear programming. The material corresponds to the second review, which prepared for the second midterm exam. Calculus -------- 1. Write a function to make polynomials in a system. The *k*-th polynomial in the system is .. math:: f_k(x_1,x_2, \ldots, x_n) = x_k + \sum_{i=1}^{n-k} x_i x_{k+i}, \quad k=1,2,\ldots,n. For example, for :math:`n=8`, the polynomials are :: x1*x2 + x2*x3 + x3*x4 + x4*x5 + x5*x6 + x6*x7 + x7*x8 + x1 x1*x3 + x2*x4 + x3*x5 + x4*x6 + x5*x7 + x6*x8 + x2 x1*x4 + x2*x5 + x3*x6 + x4*x7 + x5*x8 + x3 x1*x5 + x2*x6 + x3*x7 + x4*x8 + x4 x1*x6 + x2*x7 + x3*x8 + x5 x1*x7 + x2*x8 + x6 x1*x8 + x7 x8 2. Define a piecewise function ``int_inv_cub`` which as function of the end point :math:`b` always returns the correct value of :math:`{\displaystyle \int_{-1}^b \frac{1}{x^3} dx}`. 3. The arc length of continuous function :math:`f(x)` over an interval :math:`[a,b]` can be defined as :math:`{\displaystyle \int_a^t \sqrt{1+[f'(x)]^2}}`. 1. Compute the arc length of the positive half of the unit circle, i.e.: :math:`f(x) = \sqrt{1-x^2}` (answer :math:`= \pi`). 2. Create a function (call it ``arc_length``) in :math:`t` which returns a 10-digit floating-point approximation of the arc length of the positive half of the circle, for :math:`x \in [0,t]`. 4. Consider the recurrence relation .. math:: h(n) = 5 h(n-1) - 6 h(n-2), \quad {\rm for} \ n \geq 2, \quad {\rm with} \ h(0) = 1 \ {\rm and} \ h(1) = -2. Answer the following the questions. 1. The generating function :math:`{\displaystyle g(x) = \frac{1-7x}{1-5x + 6x^2}}` defines :math:`h(n)` as the coefficient with :math:`x^n` in the Taylor expansion of :math:`g(x)`. Use :math:`g(x)` to define :math:`h` as a function (call it ``t``) of :math:`n` which gives the value of :math:`h(n)`. 2. Write a function to compute :math:`h(n)`, directly using the recurrence relation from above. Make sure your function can compute :math:`h(120)`. Compare with the result of (a). 5. The Legendre polynomials are defined by .. math:: P_0(x) = 1, \quad P_1(x) = x, \quad P_n(x) = \frac{2n-1}{n} x P_{n-1}(x) - \frac{n-1}{n} P_{n-2}(x), \ {\rm for} \ n \geq 2. Write a efficient recursive function ``legendre`` to compute :math:`P_n(x)`. The function ``legendre`` takes on input the degree :math:`n` and the variable :math:`x`. Compare the output of your ``legendre`` (50, :math:`x` ) with the ``legendre_P`` (50, :math:`x` ). 6. Consider the point :math:`P = (1,1)` on the curve defined by :math:`xy - 2 x + 1 = 0`. Compute the slope of the tangent line to the curve at :math:`P` in two ways: 1. with implicit differentiation, 2. with a Taylor series. Plotting and Solving Equations ------------------------------ 1. Suppose we want to plot the curve :math:`x^4 + x^2 y^2 - y^2 = 0` for :math:`x` and :math:`y` both between :math:`-1` and :math:`+1`. 1. Sampling this curve as given in rectangular coordinates, how many samples do we need to take from the curve to obtain a nice plot? 2. Convert the curve into polar coordinates and plot. Give all commands used to obtain the plot. How many samples of the curve are needed here? 2. Solve :math:`x^2 a^2 - 2x^2 a - 3 x^2 - x a^2 + 4 x a - 3 x + a^2 + 2 a - 15` for :math:`x` for all values of the parameter :math:`a`. Be as complete as possible in your description of the solution. 3. Find the point with real coordinates on the curve :math:`xy - 2 x + 3 = 0` closest to the origin. 4. Consider the system .. math:: \left\{ \begin{array}{rcl} x^2 - 2 y^2 - 1 & = & 0 \\ x y - 2 x - 3 & = & 0. \\ \end{array} \right. How many real solutions does this system have? 5. Consider :math:`y'' + 6 y' + 13 y = 0`, with :math:`y(\pi/2) = -2` and :math:`y'(\pi/2) = 8`. 1. Find an exact solution to this initial value problem and use this to create a function :math:`f` which returns a numerical 10-digit floating-point approximation of the solution. 2. Solve this initial value problem numerically. Compare the solution with the value for :math:`y(2)` and also with :math:`f(2)` obtained in (a). 6. A 5-by-5 variable Toeplitz matrix has the following form: :: [t0 t1 t2 t3 t4] [t8 t0 t1 t2 t3] [t7 t8 t0 t1 t2] [t6 t7 t8 t0 t1] [t5 t6 t7 t8 t0] for the symbols in the list ``[t0, t1, t2, t3, t4, t5, t6, t7, t8]``. For general dimension :math:`n`, the :math:`(i,j)`-th element of the Toepliz matrix :math:`T` is .. math:: T_{(i,j)} = \left\{ \begin{array}{lcl} j - i & {\rm if} & j \geq i \\ j - i + 2 n - 1 & {\rm if} & j < i. \end{array} \right. Give the command(s) to define a variable Toeplitz matrix, for any dimension :math:`n`. 7. Maximize :math:`x_1 + x_2` subject to :math:`-x_1 + 2 x_2 \leq 8`, :math:`4 x_1 - 3 x_2 \leq 8`, :math:`2 x_1 + x_2 \leq 14`, :math:`x_1 \geq 0`, and :math:`x_2 \geq 0`. Write the commands to define this problem and then solve it. What are the values of :math:`x_1` and :math:`x_2` at the optimal solution?