Definition

Solution is

𝑥=(𝐴𝑇𝐴)1𝐴𝑇𝑏

If (𝐴𝑇𝐴)1 such inverse not exists, we need to use 𝑥𝐴+𝑏 from pseudo inverse (Moore-Penrose Inverse) to solve it.

Example of solving polynomial

𝑓(𝑥)=𝑐0+𝑐1𝑥+𝑐2𝑥2+𝑐3𝑥3

Given vector 𝑥 and 𝑓 as input and output, we want to find 𝑐 coefficients.

  1. build Vandermonde matrix
  2. Solve it by normal equation / pseudo inverse (Moore-Penrose Inverse)
# build Vandermonde matrix
A = np.vander(x, 4, True)
c = la.solve(A.T @ f, A.T @ A)