0
|
8628 Views
|
2 Replies
|
2 Total Likes
View groups...
Share
GROUPS:

# LeastSquares inconsistencies: Array and SparseArray objects of Complex Nums

Posted 10 years ago
 Shouldn't the following two results be identical?/The documentation says LeastSquares works on both Array and SparseArray objects/Could this be a bug in the function?...or am I not using it properly?With[{m = {{0.4472135954999579 - 0.8944271909999159 I,      0, -0.4472135954999579 + 0.8944271909999159 I},    {0, 0. - 1. I, 0. + 1. I}, {1., -1., 0}},  b = {-77.63932022500211, -80., -89.95`}}, {LeastSquares[m, b] // MatrixForm,  LeastSquares[m // SparseArray, b] // MatrixForm  } ]
2 Replies
Sort By:
Posted 10 years ago
 Thanks William!
Posted 10 years ago
 From ref/LeastSquares:The vector x is uniquely determined by the minimization only if Length[ x ] == MatrixRank[ m ].Since the rank is less than 3 (the length of x required by the dimensions of m) ---In:= m = {{0.447214 - 0.894427 I, 0, -0.447214 + 0.894427 I}, {0,     0. - 1. I, 0. + 1. I}, {1., -1., 0}};In:= b = {-77.6393, -80., -89.95};In:= MatrixRank@mOut= 2--- it's possible to get two different yet equally minimizing solutions: In:= {x1, x2} = {LeastSquares[m, b], LeastSquares[SparseArray@m, b]};  In:= Norm[m.x1 - b]  Out= 32.4636  In:= Norm[m.x2 - b]  Out= 32.4636The difference in the solution vectors could be due to differences in the methods used for dense input matrices and sparse input matrices. From ref/LeastSquares:A Method option can also be given. Settings for arbitrary-precision numerical matrices include "Direct" and "IterativeRefinement", and for sparse arrays "Direct" and "Krylov". The default setting of Automatic switches between these methods, depending on the matrix given.