Yiftach
Yiftach

Reputation: 347

Solve linear equations on a Gram matrix with numpy

Consider a case where, given an MxM matrix A and a vector b, I want to solve something of the form inv(A @ A.T) @ b (where I know A is invertible). As far as I know, it is always faster to use solve_* rather than inv. There are also variants for more efficient solving for PSD matrices (which A @ A.T must be), using Cholesky factorization.

My question - since I'm constructing the matrix A @ A.T just to immediately throw it away - is there a more specialized procedure for solving linear equations with the gram matrix of A without having to construct it?

Upvotes: 1

Views: 372

Answers (1)

jack
jack

Reputation: 1790

You can compute the factorization of A and then use that to solve your system.


Assume we want to solve

A A^T x = b

for x.

Compute the factorization of A=LU. Then solve Ay=b for y. Then solve A^T x = y for x.

This way you dont have to compute the matrix A^T A.


Note that if one has a factorization of A=LU then one can solve Ax=b as well as A^T x=b efficiently for x. This is because A^T=U^T L^T which is again a factorization of a lower times an upper triangular matrix.

Upvotes: 2

Related Questions