Reputation: 31
What method should i use?
a,b are vectors, or arrays n dimensionals, and X is (nxn) dimensional. Im using numpy for this.
I have a
X^T X a=X^T b
matrix vector equation. X,X^T,b is known and the question is a.
I have tried X^T X as X^T@X=z and doing z^-1, then z^-1@X^T =g and doing np.linalg.solve(g,b). Is there some basic linear algebra i'm doing wrong here?
Is there a specific python code for these types of equations?
Upvotes: 0
Views: 703
Reputation: 114821
"Is there a specific python code for these types of equations?"
Yes. The problem that you are solving is ordinary least squares (see also linear least squares).
NumPy has the function numpy.linalg.lstsq
for solving such problems. In your case, to compute a
given X
and b
, you would use
a, residuals, rank, singvals = np.linalg.lstsq(X, b)
residuals
, rank
and singvals
are additional information returned by lstsq
, as explained in the docstring.
Upvotes: 1