# 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

$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 $$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 $$b$$ always returns the correct value of $${\displaystyle \int_{-1}^b \frac{1}{x^3} dx}$$.

3. The arc length of continuous function $$f(x)$$ over an interval $$[a,b]$$ can be defined as $${\displaystyle \int_a^t \sqrt{1+[f'(x)]^2}}$$.

1. Compute the arc length of the positive half of the unit circle, i.e.: $$f(x) = \sqrt{1-x^2}$$ (answer $$= \pi$$).

2. Create a function (call it arc_length) in $$t$$ which returns a 10-digit floating-point approximation of the arc length of the positive half of the circle, for $$x \in [0,t]$$.

4. Consider the recurrence relation

$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.$

1. The generating function $${\displaystyle g(x) = \frac{1-7x}{1-5x + 6x^2}}$$ defines $$h(n)$$ as the coefficient with $$x^n$$ in the Taylor expansion of $$g(x)$$. Use $$g(x)$$ to define $$h$$ as a function (call it t) of $$n$$ which gives the value of $$h(n)$$.

2. Write a function to compute $$h(n)$$, directly using the recurrence relation from above. Make sure your function can compute $$h(120)$$. Compare with the result of (a).

5. The Legendre polynomials are defined by

$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 $$P_n(x)$$. The function legendre takes on input the degree $$n$$ and the variable $$x$$.

Compare the output of your legendre (50, $$x$$ ) with the legendre_P (50, $$x$$ ).

6. Consider the point $$P = (1,1)$$ on the curve defined by $$xy - 2 x + 1 = 0$$.

Compute the slope of the tangent line to the curve at $$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 $$x^4 + x^2 y^2 - y^2 = 0$$ for $$x$$ and $$y$$ both between $$-1$$ and $$+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 $$x^2 a^2 - 2x^2 a - 3 x^2 - x a^2 + 4 x a - 3 x + a^2 + 2 a - 15$$ for $$x$$ for all values of the parameter $$a$$.

Be as complete as possible in your description of the solution.

3. Find the point with real coordinates on the curve $$xy - 2 x + 3 = 0$$ closest to the origin.

4. Consider the system

$\begin{split}\left\{ \begin{array}{rcl} x^2 - 2 y^2 - 1 & = & 0 \\ x y - 2 x - 3 & = & 0. \\ \end{array} \right.\end{split}$

How many real solutions does this system have?

5. Consider $$y'' + 6 y' + 13 y = 0$$, with $$y(\pi/2) = -2$$ and $$y'(\pi/2) = 8$$.

1. Find an exact solution to this initial value problem and use this to create a function $$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 $$y(2)$$ and also with $$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 $$n$$, the $$(i,j)$$-th element of the Toepliz matrix $$T$$ is

$\begin{split}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.\end{split}$

Give the command(s) to define a variable Toeplitz matrix, for any dimension $$n$$.

7. Maximize $$x_1 + x_2$$ subject to $$-x_1 + 2 x_2 \leq 8$$, $$4 x_1 - 3 x_2 \leq 8$$, $$2 x_1 + x_2 \leq 14$$, $$x_1 \geq 0$$, and $$x_2 \geq 0$$.

Write the commands to define this problem and then solve it. What are the values of $$x_1$$ and $$x_2$$ at the optimal solution?