Lecture 33: the Second Midterm Exam =================================== The second midterm exam covers parts three and four of the course. Questions on the Spring 2017 Second Midterm Exam ------------------------------------------------ The list of questions on the Spring 2017 second midterm exam are below. The exam is open book, open notes and open computer. All answers to the questions must be handwritten, submitted on paper. 1. Consider the formula .. math:: {\displaystyle \ln(2) = \sum_{k=1}^\infty \frac{1}{k 2^k}}. Make a function ``f(k)`` that returns the value of :math:`1/(k 2^k)`. Use this function in a list comprehension to compute the first 100 bits of :math:`\ln(2)`. How accurate is this approximation for :math:`\ln(2)`? Write the magnitude of the error. 2. The recurrence .. math:: \displaystyle S(n) = \frac{1}{n} ((6 n - 9) S(n-1) - (n-3)S(n-2)) is valid for :math:`n > 1`. For :math:`n=0` and :math:`n=1`, we have :math:`S(0) = 1` and :math:`S(1) = 1`. Use the recurrence for :math:`S` to define an *efficient* function to compute :math:`S(n)`. How many decimals do you see in the number :math:`S(100)`? 3. Consider the curve :math:`y^4 - y^3 + 2 x^2 y^2 + 3 x^2 y + x^4 = 0`. 1. Give the command(s) to make a plot of this curve, for :math:`x \in [-1, +1]` and :math:`y \in [-0.7, +1]`. 2. Write the representation of this curve in polar coordinates. Give all relevant commands you used. 3. What is the command to plot this curve in polar coordinates? 4. Consider the Taylor series of :math:`\log(1+x)` at :math:`x = 0`. Use ``sympy`` to define a generator for the next term in the Taylor series. Illustrate the use of this generator to compute a list of the first 10 terms. 5. Let :math:`f(x,y) = x^4 + x^2 y^2 + y^4 - x (x^2 + y^2)` and :math:`P = (2/3,2/3)`. Compute the slope of the tangent line of the curve defined by :math:`f` at the point :math:`P`. Write the value for the slope and the commands you used. 6. Consider the polynomial system defined by :math:`p = x^3 y - 3 x^2 + 9` and :math:`q = 4 x y^2 + x y - 7`. Construct a lexicographic Groebner basis for the ideal defined by the polynomials :math:`p` and :math:`q`. How many solutions does the polynomial system have? 7. Let :math:`A` be an :math:`n`-dimensional matrix with its elements indexed by :math:`i` and :math:`j`, defined by: 1. For :math:`i=j`, the :math:`(i,j)`-th element of :math:`A` is zero. 2. For :math:`i \not= j`, the :math:`(i,j)`-th element of :math:`A` is :math:`+1` if :math:`i+j` is even and :math:`-1` if :math:`i+j` is odd. Write all commands for the following: 1. Define the matrix :math:`A`, for :math:`n = 17`. Let :math:`{\bf b}` be a 17-dimensional vector of ones. 2. Solve the linear system :math:`A {\bf x} = {\bf b}`. Verify the residual: the norm of :math:`{\bf b} - A {\bf x}`. Write the sum of the coordinates in the solution :math:`{\bf x}`. Questions on the Fall 2018 Second Midterm Exam ---------------------------------------------- The list of questions on the Fall 2018 second midterm exam are below. The exam is open book, open notes and open computer. All answers to the questions must be handwritten, submitted on paper. 1. Define a function :math:`f` which takes on input a list of variables :math:`[x_1, x_2, \ldots , x_n]` and an index :math:`k`. The function :math:`f([x_1, x_2, \ldots, x_n], k)` returns the expression .. math:: x_k \sum_{\substack{i=1 \\i \neq k}}^n x_i^2 - x_k + 1 = x_k \left( - x_k^2 + x_1^2 + x_2^2 + \cdots + x_n^2 \right) - x_k + 1. Write the definition of the function :math:`f`. 2. The number of ways to put parentheses in a chain of multiplications of :math:`n` matrices of compatible dimension equals :math:`f(n)`. The recursive definition for :math:`f(n)` is .. math:: f(1) = 1 \quad \mbox{and for } n>1, \quad f(n) = \sum_{k=1}^{n-1} f(k) f(n-k). 1. Write an efficient recursive definition of the function :math:`f`. 2. How many decimal places does the number :math:`f(100)` have? 3. Consider the curve defined by the equation :math:`x y - x^2 - y^3 + 1 = 0` and the point :math:`(1, 1)`. 1. Compute the equation of the tangent line to the curve at the point. 2. What is the slope of the tangent line? 4. Write the commands to set up the system that needs to be solved to compute the point on the curve :math:`x y - x^2 - y^3 + 1 = 0` closest to :math:`(0,0)`. Do not solve the system. 5. Consider the curve defined by :math:`(x^2+y^2)(y^2 + x(x+1)) - 4 x y^2 = 0`. 1. Make a plot of the curve for :math:`x` and :math:`y` both in :math:`[-3/2,3/2]`. Choose sufficiently many points to obtain a smooth plot. 2. Convert the formulation of the curve into polar coordinates. 3. Write the command to make the plot in polar coordinates. How many times does the curve pass through the origin? 6. Consider :math:`p = x^3 y + 2 x y - 3 y^2 + 1` and :math:`q = 2 x y^2 - 5 y^2 + 7 y - 3` as polynomials with rational coefficients. 1. Write all relevant commands to compute a Groebner basis for a lexicographical term order. 2. How many solutions with complex coordinates do you expect? Explain! 7. The :math:`(i,j)`-th entry in an :math:`n`-dimensional Redheffer matrix, for :math:`i` and :math:`j` both ranging between 1 and :math:`n`, is one if :math:`i` divides :math:`j` or if :math:`j = 1`, and zero otherwise. Write all relevant commands for the following. 1. Define a 10-by-10 Redheffer matrix stored as a matrix :math:`A`. 2. Define a right hand side vector :math:`{\bf b}` of all ones. Solve the linear system :math:`A {\bf x} = {\bf b}`. Compute the residual vector and its norm. Questions on the Spring 2019 Second Midterm Exam ------------------------------------------------ The list of questions on the Spring 2019 second midterm exam are below. The exam is open book, open notes and open computer. All answers to the questions must be handwritten, submitted on paper. 1. For any two positive natural numbers :math:`n` and :math:`d`, consider .. math:: {\displaystyle f_k(x_1, x_2, \ldots, x_n) = \left( \prod_{i=0}^d x_{[(k+i) \!\!\!\! \mod (n+1)]} \right) - x_k + 1 = x_k x_{k+1} \cdots x_{(k+d) \!\!\!\! \mod (n+1)} - x_k + 1}, for :math:`k=1,2, \ldots, n.` Give a definition of a function ``f`` which takes on input :math:`X = [x_1, x_2, \ldots, x_n]`, a list of :math:`n` variables, and :math:`k`, :math:`n`, :math:`d`. The function ``f``:math:(`X,k,n,d`) returns :math:`f_k(x_1,x_2,\ldots,x_n)`. 2. Bessel polynomials are defined recursively as :math:`B_0(x) = 1`, :math:`B_1(x) = x+1`, and :math:`B_n(x) = (2 n-1) x B_{n-1}(x) + B_{n-2}(x)`, for :math:`n > 1`. Write the definition of an *efficient, recursive* function ``B`` which takes on input :math:`n` and :math:`x`. ``B``:math:`(n,x)` returns :math:`B_n(x)`. What is the coefficient of :math:`x` in :math:`B_{50}(x)`? 3. Consider the point :math:`P = (2,1)` on the curve :math:`x^2 - y^3 - y - 2 = 0`. Compute the slope of the tangent line at :math:`P` to the curve. Write all relevant Sage commands. What is the value of the slope? 4. Describe the functionality of the ``assume`` command. Give an example of a good application. What problem does ``assume`` solve? 5. Consider the curve defined by :math:`x^6 + 3 x^4 y^2 + 3 x^2 y^4 + y^6 - 4 x^5 + 4 x y^4 + 4 x^4 - 12 x^2 y^2 = 0`. 1. Write the instruction to draw the curve as given by the polynomial above. Does the curve pass through the origin? 2. Convert the polynomial into polar coordinates. Write the expression of the curve in polar coordinates. 3. Plot the curve in polar coordinates. How may times does the curve pass through the origin? 6. Consider the surface :math:`x^2 + y^2 - z^2 = 0` and the point :math:`P = (3,2,1)`. Find the point on the surface closest to :math:`P`. 1. Write the commands to set up the system that needs to be solved. 2. What solving command(s) do you use? 3. What is the (approximate) distance of the closest point? 7. Maximize :math:`8x_1 + 11x_2` subject to :math:`x_1 + x_2 \leq 8`, :math:`-x_1 + 3 x_2 \leq 12`, :math:`x_1 \geq 0`, and :math:`x_2 \geq 0`. Write the commands to define this problem and then solve it. What is the value of the optimal solution? Questions on the Summer 2022 Second Midterm Exam ------------------------------------------------ The exam in the summer 2022 took 100 minutes and was administered online, in two different versions. Questions had to be uploaded into one single Jupyter notebook into gradescope. The list of the nine questions on the first version is below. 1. Consider the general formula, for positive integers \ :math:`k`, \ :math:`n`, and \ :math:`d`: .. math:: f_k(x_1, x_2, \ldots, x_n) = x_k^d + \sum_{i=1}^d \left[ x_{(k+i) \mbox{ mod } n} \left( 1 - x_{(k+i+1) \mbox{ mod } n} \right) \right] - 1. Give a definition of a function \ :math:`{\tt f}` which takes on input \ :math:`X = [x_1, x_2, \ldots, x_n]`, a list of \ :math:`n` variables, and \ :math:`k`, \ :math:`d`, \ :math:`n`. The function \ :math:`{\tt f}(X,k,d,n)` returns \ :math:`f_k(x_1,x_2,\ldots,x_n)`. Show the output of your function for \ :math:`d=3`, \ :math:`n=8`, and \ :math:`k=5`. 2. The sequence of Fibonacci polynomials is defined as .. math:: f_0(x) = 0, f_1(x) = 1, \mbox{ and } f_n(x) = x f_{n-1}(x) + f_{n-2}(x), \mbox{ for all } n > 1. Write the definition of an *efficient, recursive* function \ :math:`{\tt F}` which takes on input \ :math:`n` and \ :math:`x`. \ :math:`{\tt F}(n, x)` returns \ :math:`f_{n}(x)`. Compute \ :math:`{\tt F}(50, x)`. 3. Consider the point \ :math:`P = (2,1)` on the curve \ :math:`x^2 y^3 - y^2 - 2 x + 1 = 0`. Compute the slope of the tangent line at \ :math:`P` to the curve. 4. Explain the difference between a symbolic factorization and a symbolic-numeric factorization of a polynomial in one variable. Illustrate the difference with a good example. 5. Plot the surface defined by \ :math:`x(u, v) = 2u/(u^2 + v^2 + 1)`, \ :math:`y(u, v) = 2v/(u^2 + v^2 + 1)`, and \ :math:`z(u, v) = (u^2 + v^2 - 1)/(u^2 + v^2 + 1)`, for \ :math:`u` and \ :math:`v` both in the interval \ :math:`[-4, 4]`. Describe what you see. Can you name the surface? 6. Consider the *n*-dimensional tridiagonal matrix \ :math:`A_n` with \ :math:`x` on the diagonal, and ones on the upper and lower diagonal. For example, for \ :math:`n = 5`: .. math:: A_5 = \left[ \begin{array}{ccccc} x & 1 & 0 & 0 & 0 \\ 1 & x & 1 & 0 & 0 \\ 0 & 1 & x & 1 & 0 \\ 0 & 0 & 1 & x & 1 \\ 0 & 0 & 0 & 1 & x \end{array} \right]. 1. Write the instructions to define \ :math:`A_n`. Plain typing all elements in all rows and columns will receive no credit, your solution should scale well for any dimension. 2. Compute the determinant of \ :math:`A_5`. 7. Consider the surface \ :math:`z = x^2 - y^2` and the point \ :math:`P = (2,1,3)`. Find the point on the surface closest to \ :math:`P`. 1. Formulate the target function (square of the distance to \ :math:`P`) and solve the problem. 2. What is the (approximate) distance of the closest point? 8. What is the Laplace transform of a function? Illustrate your explanation with a good example. 9. Maximize \ :math:`2 x_1 + x_2` subject to \ :math:`-x_1 + 2 x_2 \leq 8`, \ :math:`4 x_1 - 3 x_2 \leq 9`, \ :math:`2 x_1 + x_2 \leq 13`, \ :math:`x_1 \geq 0`, and \ :math:`x_2 \geq 0`. Define this problem and then solve it. The list of the nine questions on the second version is below. 1. Consider the general formula, for positive integers \ :math:`k`, \ :math:`n`, and \ :math:`d`: .. math:: f_k(x_1, x_2, \ldots, x_n) = x_k^d + \sum_{i=1}^d \left( \frac{x_{(k+i) \mbox{ mod } n}}{x_{(k+i+1) \mbox{ mod } n}} \right) - 1. Give a definition of a function \ :math:`{\tt f}` which takes on input \ :math:`X = [x_1, x_2, \ldots, x_n]`, a list of \ :math:`n` variables, and \ :math:`k`, \ :math:`d`, \ :math:`n`. The function \ :math:`{\tt f}(X,k,d,n)` returns \ :math:`f_k(x_1,x_2,\ldots,x_n)`. Show the output of your function for \ :math:`d=3`, \ :math:`n=8`, and \ :math:`k=5`. 2. The sequence of Lucas polynomials is defined as .. math:: \ell_0(x) = 2, \ell_1(x) = x, \mbox{ and } \ell_n(x) = x \ell_{n-1}(x) + \ell_{n-2}(x), \mbox{ for all } n > 1. Write the definition of an *efficient, recursive* function \ :math:`{\tt L}` which takes on input \:math:`n` and \ :math:`x`. :math:`{\tt L}(n, x)` returns \ :math:`\ell_{n}(x)`. Compute \ :math:`{\tt L}(50, x)`. 3. Consider the point \ :math:`P = (3,1)` on the curve \ :math:`x^2 - 2 x y + y^3 - 4 = 0`. Compute the slope of the tangent line at \ :math:`P` to the curve. 4. Explain the difference between a numeric factorization and a symbolic-numeric factorization of a polynomial in one variable. Illustrate the difference with a good example. 5. Plot the space curve defined by \ :math:`(\pm \sqrt{1 - t^4}, t^2, t)`, for \ :math:`t \in [-1, +1]`, using the color red. Demonstrate with a plot that this curve lies in the intersection of the cylinders \ :math:`x^2 + y^2 - 1 = 0` and \ :math:`y - z^2 = 0`, using blue and green to color the cylinders. 6. Consider the *n*-dimensional tridiagonal matrix \ :math:`A_n` with \ :math:`2x` on the diagonal, and ones on the upper and lower diagonal. For example, for \ :math:`n = 5`: .. math:: A_5 = \left[ \begin{array}{ccccc} 2x & 1 & 0 & 0 & 0 \\ 1 & 2x & 1 & 0 & 0 \\ 0 & 1 & 2x & 1 & 0 \\ 0 & 0 & 1 & 2x & 1 \\ 0 & 0 & 0 & 1 & 2x \end{array} \right]. 1. Write the instructions to define \ :math:`A_n`. Plain typing all elements in all rows and columns will receive no credit, your solution should scale well for any dimension. 2. Compute the determinant of \ :math:`A_5`. 7. Consider the surface \ :math:`z = x^2 - y^2` and the point \ :math:`P = (3,2,1)`. Find the point on the surface closest to \ :math:`P`. 1. Formulate the target function (square of the distance to \ :math:`P`) and solve the problem. 2. What is the (approximate) distance of the closest point? 8. Consider the initial value problem .. math:: \frac{d^2 y}{d x^2} + 2 \frac{d y}{d x} + 3 y = \sin(x), \quad y(0) = 1, \quad y'(0) = 0. Define this problem and solve it. Plot the solution for \ :math:`x \in [0,20]` and describe the shape of the solution. 9. What is the V-representation of a polygon? Illustrate your explanation with a good example.