2

I sloved a least square problem (Ax=b for A ) using pinv in numpy and (pinv , lstsq) in scipy and "/" in matlab. I got some different answers, so what is the different between them?

problem :Ax=b for A

method:

  1. pinv in numpy and scipy : A=b*pinv(x)

  2. lstsq in scipy : A.T=lstsq(x.T,b.T) , the problem has changed to (x.T*A.T=b.T)

  3. / in matlab : A=b/x

matlab: https://cn.mathworks.com/help/matlab/ref/mrdivide.html

"x = B/A solves the system of linear equations xA = B for x. The matrices A and B must contain the same number of columns. If A is a rectangular m-by-n matrix with m ~= n, and B is a matrix with n columns, then x = B/A returns a least-squares solution of the system of equations xA = B. "

scipy.linalg.lstsq:Compute least-squares solution to equation Ax = b.

scipy.linalg.pinv:Compute the (Moore-Penrose) pseudo-inverse of a matrix. Calculate a generalized inverse of a matrix using a least-squares solver.

numpy.linalg.pinv:Calculate the generalized inverse of a matrix using its singular-value decomposition (SVD) and including all large singular values.

user24067
  • 31
  • 1
  • 9
  • 1
    Matlab pinv is different than (back)slash also (see [here](https://www.mathworks.com/matlabcentral/newsreader/view_thread/39549)). It uses QR rather than SVD. – GeoMatt22 Jul 29 '17 at 16:56
  • Read [this answer of mine](https://stackoverflow.com/a/36166625/5211833) on what the backslash operator actually does. The forward slash is a division, which is usually used element wise and not for least squares problems, that's what the backslash is for. – Adriaan Jul 29 '17 at 17:18
  • @Adriaan "x = B/A solves the system of linear equations x*A = B for x. The matrices A and B must contain the same number of columns. If A is a rectangular m-by-n matrix with m ~= n, and B is a matrix with n columns, then x = B/A returns a least-squares solution of the system of equations x*A = B. [link](https://cn.mathworks.com/help/matlab/ref/mrdivide.html) – user24067 Jul 30 '17 at 07:44

0 Answers0