sloisel / numeric

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

Issue with numeric.echelonize #44

Closed omphalos closed 11 years ago

omphalos commented 11 years ago

Hello, I want to say first of all what a nice library I think numeric is.

I am using numeric.echelonize and am running into a little problem.

numeric.echelonize([[1,2],[0,0]])

This returns:

{ I: [ [ Infinity, -Infinity ], [ -Infinity, Infinity ] ],
  A: [ [ NaN, NaN ], [ NaN, NaN ] ],
  P: [ 1, 0 ]
}

Looking at the code this seems to be due to divide-by-zero inside diveq.

I may be misunderstanding this function since I don't see documentation for it, but from its name my guess is that it is supposed to be calculating echelon form. In that case I would expect numeric.echelonize([[1,2],[0,0]]) to return numbers instead of Infinity and NaN for I (pseudoinverse?) and A (echelonized matrix?).

sloisel commented 11 years ago

numeric.echelonize() is used internally by some of the optimization routines to parametrize a constrained search space. That being said, you're also obviously free to use it! It takes a rectangular matrix of full rank and (attempts to) put it in reduced echelon form. The problem with the example you give is that your matrix is rank deficient. Although your particular matrix is obviously rank deficient and there's no numerical issues in verifying it, it is generally numerically difficult to check whether a matrix has full rank. The best way to do this is to use the SVD and look at how many singular values are nonzero.

omphalos commented 11 years ago

Got it. Thank you for the explanation.