sloisel / numeric

Numerical analysis in Javascript
http://www.numericjs.com/
Other
1.42k stars 176 forks source link

Internal error on eigenvalues of zero matrices. #50

Open dantswain opened 10 years ago

dantswain commented 10 years ago

I noticed some errors on computing the eigenvalues of zero matrices (matrices consisting of all zeros).

Test definitions:

IN> numeric.eig([0]) 
OUT> {lambda: {x: [0], y: [0]},
      E: {x: [1], y: [0]}}
IN> numeric.eig([[0, 0], [0, 0]]) 
OUT> {lambda: {x: [0, 0], y: [0, 0]}, 
      E: {x: [[1, 0], [0, 1]],
          y: [[0, 0], [0, 0]] }}
IN> numeric.eig([[0, 0, 0], [0, 0, 0], [0, 0, 0]]) 
OUT> {lambda: {x: [0, 0, 0], y: [0, 0, 0]}, 
      E: {x: [[1, 0, 0], [0, 1, 0], [0, 0, 1]],
          y: [[0, 0, 0], [0, 0, 0], [0, 0, 0]] }}

Results:

132 FAIL numeric.eig([0])==>Error:numeric:toUpperHessenberg()onlyworksonsquarematrices!=={lambda:{x:[0],y:[0]},E:{x:[1],y:[0]}}
133 FAIL numeric.eig([[0,0],[0,0]])==>{lambda:{x:[0,0],y:},E:{x:[[1,1],[0,0]],y:}}!=={lambda:{x:[0,0],y:[0,0]},E:{x:[[1,0],[0,1]],y:[[0,0],[0,0]]}}
134 FAIL numeric.eig([[0,0,0],[0,0,0],[0,0,0]])==>Error:eig:internalerror!=={lambda:{x:[0,0,0],y:[0,0,0]},E:{x:[[1,0,0],[0,1,0],[0,0,1]],y:[[0,0,0],[0,0,0],[0,0,0]]}}

The size 1 case is degenerate, but should still work. The size 2 case correctly identifies the eigenvalues as zero (multiplicity 2) but doesn't choose eigenvalues to span the space. The size 3 case fails on an error in the house function. All cases could probably be handled by checking if the matrix is a zero matrix and then just returning zeros as the eigenvalues and the identity matrix as the eigenvector generator.

sloisel commented 10 years ago

There's a bug with matrices with repeated eigenvalues. I haven't had the time to fix it.

On Tue, Nov 19, 2013 at 2:57 AM, Dan notifications@github.com wrote:

I noticed some errors on computing the eigenvalues of zero matrices (matrices consisting of all zeros).

Test definitions:

IN> numeric.eig([0]) OUT> {lambda: {x: [0], y: [0]}, E: {x: [1], y: [0]}} IN> numeric.eig([[0, 0], [0, 0]]) OUT> {lambda: {x: [0, 0], y: [0, 0]}, E: {x: [[1, 0], [0, 1]], y: [[0, 0], [0, 0]] }} IN> numeric.eig([[0, 0, 0], [0, 0, 0], [0, 0, 0]]) OUT> {lambda: {x: [0, 0, 0], y: [0, 0, 0]}, E: {x: [[1, 0, 0], [0, 1, 0], [0, 0, 1]], y: [[0, 0, 0], [0, 0, 0], [0, 0, 0]] }}

Results:

132 FAIL numeric.eig([0])==>Error:numeric:toUpperHessenberg()onlyworksonsquarematrices!=={lambda:{x:[0],y:[0]},E:{x:[1],y:[0]}} 133 FAIL numeric.eig([[0,0],[0,0]])==>{lambda:{x:[0,0],y:},E:{x:[[1,1],[0,0]],y:}}!=={lambda:{x:[0,0],y:[0,0]},E:{x:[[1,0],[0,1]],y:[[0,0],[0,0]]}} 134 FAIL numeric.eig([[0,0,0],[0,0,0],[0,0,0]])==>Error:eig:internalerror!=={lambda:{x:[0,0,0],y:[0,0,0]},E:{x:[[1,0,0],[0,1,0],[0,0,1]],y:[[0,0,0],[0,0,0],[0,0,0]]}}

The size 1 case is degenerate, but should still work. The size 2 case correctly identifies the eigenvalues as zero (multiplicity 2) but doesn't choose eigenvalues to span the space. The size 3 case fails on an error in the house function. All cases could probably be handled by checking if the matrix is a zero matrix and then just returning zeros as the eigenvalues and the identity matrix as the eigenvector generator.

— Reply to this email directly or view it on GitHubhttps://github.com/sloisel/numeric/issues/50 .

Sébastien Loisel Department of Mathematics Heriot-Watt University Riccarton EH14 4AS United Kingdom web: http://www.ma.hw.ac.uk/~loisel/ email: S.Loisel at hw.ac.uk phone: +44 131 451 3234 fax: +44 131 451 3249