mathjs
mathjs copied to clipboard
Add a function that only finds eigenvalues, not eigenvectors
The current implementation of eigs for complex matrices (see PR #1743) starts with finding eigenvalues and then proceeds to find eigenvectors. Since not everybody needs eigenvectors, a significant portion of time could be saved by skipping this part. This is one small step towards fixing #1175.
👍 makes sense
May I work on this?
Yes, definitely :)
The algorithms you'll want to use are in /src/function/matrix/eigs/. I'm not sure about the algorithm for real symmetric matrices, but the one for complex matrices has a boolean argument indicating whether it sould find eigenvectors or not, so the implementation should be fairly simple there.
Thanks for your offer @Priyaraj17 👍
Since the flag to only find eigenvalues is already there in src/function/matrix/eigs/complexEigs.js, it would only take a small change to the definition of the eigs() function to enable this. (The overhead of eigenvectors in the real symmetric case is much less, and so at least as a first pass you could just compute them and throw them away in that case.) So this would still be a potentially worthwhile change. Allowing the second argument to eigs to be a options object with properties precision (a number) and/or eigenvectors (a boolean, defaulting to true), but when it is just a number interpreting it as precision, would be a plausible non-breaking way to achieve this. Or possibly since we are about to break anyway (see #3032), would we want to just change the second argument of eigs() to have to be such an options object? Just a thought, I could do a quick PR in time for v12 if desired.
Great idea!
It would be neat to change the syntax of eigs and complexEigs to have an object with options { precision?: number, eigenvectors?: boolean }. I'm also wondering about the second argument of complexEigs, the size of the matrix N, that could be easily determined inside the function itself.
Right now, complexEigs is not exposed in the public API, it is only used internally inside eigs, so we can change the syntax as we like. I would like to keep the arguments of eigs backward compatible so it's not a breaking change, and I think that is perfectly possible: then it has the following syntax:
eigs(x)
eigs(x, precision)
eigs(x, options) // options: { precision?, eigenvectors? }
Fixed now in v12.0.0 via #3057.