0

I have a matrix A with shape (224, 45). It's rank is 44. When I try this code:

solution = np.linalg.lstsq(A, rhs)[0]

I get solution with very high values, something like 1e14.

When I try

solution = np.linalg.lstsq(A.T.dot(A), A.T.dot(rhs))[0]

I get good solution, as expected.

The question is do I need to use np.linalg.lstsq only for square symmetric matrices or something like this? There is nothing about it in docs.

Andrey
  • 99
  • 1
  • 7
  • Just because your `solution` contains large values doesn't necessarily mean that it is invalid. Have you looked at `A.dot(solution) - rhs`? – ali_m Nov 23 '15 at 21:00
  • Yes, I've looked. The norm of error `A.dot(solution) - rhs` is quite large, however, the relative error is small. The most interesting thing is that if I plot the results, I get the same picture, but it is displaced. – Andrey Nov 23 '15 at 21:08
  • I'm solving a problem of finding coordinates of positions of objects having different observations. Maybe the displacement simply means the movement of the whole set of objects in the global space, because their relative positions remain the same whether I use the first or the second method. – Andrey Nov 23 '15 at 21:12
  • 3
    That's expected - since you are trying to solve an underdetermined system then there are an infinite number of equally good least-squares solutions that are displacements of one another within the nullspace of `A`. – ali_m Nov 23 '15 at 21:30
  • @ali_m thank you! That's really an explanation of what I observe. – Andrey Nov 23 '15 at 21:35
  • You might find this helpful: http://stackoverflow.com/a/33620007/1461210 – ali_m Nov 23 '15 at 21:38

0 Answers0