For a symmetric positive definite matrix A∈Rd×d and a square matrix B∈Rd×d, how do you derive ∇Atr⁡(BA) and ∇Alog⁡det⁡(A), and how does ∇Σlog⁡det⁡(Σ) appear in fitting a multivariate Gaussian by maximum likelihood?

Linear algebra and optimisation, Matrix calculus
Level L3 Intermediate. Length Medium. Nature Mat Mathematical.

What's being asked

Whether you can differentiate trace and log-determinant functions using differentials and connect them to Gaussian covariance estimation.

Key idea

Writing a scalar change df=tr⁡(G⊤dA) immediately identifies the gradient ∇Af=G: for f(A)=tr⁡(BA) this gives B⊤, and Jacobi's formula d(log⁡det⁡A)=tr⁡(A−1 dA) gives ∇Alog⁡det⁡(A)=A−⊤=A−1 for symmetric A.

Steps

  1. Use the differential–trace rule: for scalar f(A), ∇Af is the unique matrix satisfying df=∑i,j(∇Af)ij dAij=tr⁡((∇Af)⊤dA).
  2. Differentiate tr⁡(BA): since trace is linear, dtr⁡(BA)=tr⁡(B dA)=tr⁡((B⊤)⊤dA), so ∇Atr⁡(BA)=B⊤; in coordinates, ∂∂Aij∑p,qBpqAqp=Bji.
  3. Derive ∇Alog⁡det⁡(A) via cofactor expansion: ∂det⁡(A)∂Aij=Cij (the (i,j) cofactor), and A−1=1det⁡(A)C⊤, so ∂log⁡det⁡(A)∂Aij=Cijdet⁡(A)=(A−⊤)ij.
  4. Equivalently via Jacobi's formula, d(log⁡det⁡A)=d(det⁡A)det⁡A=tr⁡(A−1 dA), which matches ∇Alog⁡det⁡(A)=A−⊤, simplifying to A−1 when A is symmetric.
  5. Connect to Gaussian MLE: for n data vectors xi∈Rd and mean μ (equal to the sample mean 1n∑i=1nxi at the MLE), the Gaussian log-likelihood equals −n2log⁡det⁡(Σ)−12tr⁡(Σ−1S) up to an additive constant, where S=∑i=1n(xi−μ)(xi−μ)⊤. Rewriting −log⁡det⁡(Σ)=log⁡det⁡(Σ−1) and setting the gradient with respect to Σ−1 to zero uses ∇Σ−1log⁡det⁡(Σ−1)=Σ and ∇Σ−1tr⁡(Σ−1S)=S⊤=S to give n2Σ−12S=0, hence Σ^=1nS (equivalently, differentiating directly with respect to Σ uses ∇Σlog⁡det⁡(Σ)=Σ−1 to give −n2Σ−1+12Σ−1SΣ−1=0).

Common mistakes

How long your answer should be

Half a page; 4–5 minutes.

Last checked on 4 December 2026.

Read this

Previous in Linear algebra and optimisation: How is the Moore–Penrose pseudoinverse A+ defined from the SVD A=UΣV⊤, what does x∗=A+b compute in general, and what are A+ and x∗ for A=(1224) and b=(36)?
Next in Linear algebra and optimisation: What is the ℓ2 condition number κ2(A) of an invertible matrix A, how does it bound the relative sensitivity of Ax=b to perturbations in b, and what happens for A=(1019999101) when b=(200200) is perturbed by δb=(2−2)?