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