human
What is a code to (a) and the other steps required given the following:
(a)
Let $f(x)=x^7$. Evaluate the derivative matrix and the derivatives at quadrature points using Gauss-Lobatto-Legendre quadrature with $Q=7,\ 8,\ 9$."
Please write code following the instructions in jupyter notebook style.
assistant
#Here is code to (a) and the other steps required.

def f_ex2a(x):
    """f = x^7"""
    
    return x**7

def df_ex2a(x):
    """df/dx = 7 * (x**6)"""
    
    return 7 * (x**6)

def ex2a(Qi, f, df):
    """a wrapper for generating solutions"""
    
    numpy.set_printoptions(
        formatter={'float': "{:5.2e}".format}, linewidth=120)
    
    qd = quad.GaussLobattoJacobi(Qi)
    p = poly.LagrangeBasis(qd.nodes)
    D = p.derivative(qd.nodes)
    ans = D.dot(f(qd.nodes))
    exact = df(qd.nodes)
    err = numpy.abs(ans - exact)
    
    def generateLatex(A):
        return "{\\scriptsize \\left[\\begin{array}{r}" + \
                re.sub(r"[ ]+", "&", re.sub(r"\n[ ]*", "\\\\\\\\", 
                re.sub(r"\][ ]*", "", re.sub(r"\[[ ]*", "", str(A))))) + \
               "\\end{array}\\right]}"
            
    display(Latex("For " + "$Q={0}$".format(Qi) + ":"))
    display(Latex("$\qquad$The derivative matrix is: "))
    display(Math("\\qquad" + generateLatex(D)))
    display(Latex("$\\qquad$The derivatives at quadrature points are: "))
    display(Math("\\qquad" + generateLatex(ans)))
    display(Latex("$\\qquad$The exact derivatives at quadrature points are: "))
    display(Math("\\qquad" + generateLatex(exact)))
    display(Latex("$\\qquad$The absolute errors are: "))
    display(Math("\\qquad" + generateLatex(err)))

for Qi in [7, 8, 9]:
    ex2a(Qi, f_ex2a, df_ex2a)