Message Boards Message Boards

0
|
9110 Views
|
2 Replies
|
2 Total Likes
View groups...
Share
Share this post:

LeastSquares inconsistencies: Array and SparseArray objects of Complex Nums

Posted 11 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
  }
 ]
POSTED BY: Todor Latev
2 Replies
Posted 11 years ago
Thanks William!
POSTED BY: Todor Latev
Posted 11 years ago
From ref/LeastSquares:
The vector x is uniquely determined by the minimization only if Length[ ] == MatrixRank[ ].

Since the rank is less than 3 (the length of x required by the dimensions of m) ---
In[1]:= m = {{0.447214 - 0.894427 I, 0, -0.447214 + 0.894427 I}, {0,
    0. - 1. I, 0. + 1. I}, {1., -1., 0}};

In[2]:= b = {-77.6393, -80., -89.95};

In[3]:= MatrixRank@m

Out[3]= 2
--- it's possible to get two different yet equally minimizing solutions:
 In[4]:= {x1, x2} = {LeastSquares[m, b], LeastSquares[SparseArray@m, b]};
 
 In[5]:= Norm[m.x1 - b]
 
 Out[5]= 32.4636
 
 In[6]:= Norm[m.x2 - b]
 
 Out[6]= 32.4636

The 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.
POSTED BY: William Rummler
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract