Sage coding

[Problem 1] The Eulerian polynomials An(t) are defined by the following recurrence:
A0(t) = 1
An(t) = t(1 − t)A
0
n−1
(t) + An−1(t)(1 + (n − 1))t for n ≥ 1 .
We’ll first compute these in three different ways, and then find the roots of these polynomials:
(a) Write a Sage function eulRec which takes in a number n and uses ordinary recursion and outputs
the nth Eulerian polynomial An(t). Provide the output for eulRec(4) as part of your answer.
(b) Write a Sage function mEulRec which takes in a number n and outputs the Eulerian polynomial
An(t) using memoization. Provide the output for mEulRec(5) as part of your answer.
(c) Write a Sage function eulDirect which computes An(t) using the exact identity
An(t) = (1 − t)
n+1X∞
j=0
t
j
(j + 1)n
.
Be sure to simplify so that your output is a polynomial! Provide the output for eulDirect(6) as part
of your answer.
(d) Write a Sage function eulRoots() which takes in a number n and outputs a list containing the roots
of the nth Eulerian polynomial An. Provide the output for eulRoots(10) as part of your answer.
[Problem 2] Write a Sage function problem2(d,j) which takes in an integer d ≥ 1 and j ≥ 1 and does the
following: Generate a random polynomial f(x) = a0 + a1x + · · · + adx
d of degree d where the coefficients
aj are chosen uniformly at random to be +1 or −1 with probability 1/2 each. The function should print
the polynomial f and also the following plot: the roots of f, f0
, f00, . . . , f(j) are plotted where the roots of
f are in red, roots of f
0 are in blue, roots of f
00 (if j ≥ 2) are in red, and so on. In other words, the roots
of f
(i)
for i ≤ j are in red if i is even, and in blue if i is odd. Provide the output for problem2(40,10) as
part of your answer.
[Problem 3] Recall that given a function f(x, y) the critical points are the solutions to the system
∂f
∂x(x, y) = 0
∂f
∂y (x, y) = 0 .
The second derivative test is based on the function
D(x, y) = fxx(x, y)fyy(x, y) − (fxy(x, y))2
and is used to classify critical points. In particular, if (x0, y0) is a critical point of f then we have the
following cases
• If D(x0, y0) > 0 and fxx(x0, y0) > 0 then (x0, y0) is a local min.
• If D(x0, y0) > 0 and fxx(x0, y0) > 0 then (x0, y0) is a local max.
• If D(x0, y0) < 0 then (x0, y0) is a saddle point.