Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Odd EigenVector calculation #13

Open
wraith1995 opened this issue Feb 29, 2016 · 3 comments
Open

Odd EigenVector calculation #13

wraith1995 opened this issue Feb 29, 2016 · 3 comments

Comments

@wraith1995
Copy link

Hi,
Jmat.eig([[-1,0,1],[3,0,-3],[1,0,-1]]).v.toString() gives us the following:

answer: [[-1.0000000000000002, 1.0000000000000113, 0], [2.9999999999999987, -50.64166161063003, 1], [1, 1, 0]]

(as tested here: http://lodev.org/jmat/jmat_demo.html and in the browser)

Everything is close enough except that -50.64166161063003 should be 0. (See: http://www.wolframalpha.com/input/?i=%7B%7B-1,0,1%7D,%7B3,0,-3%7D,%7B1,0,-1%7D%7D)

I just kind of wandered into this so I thought that I might report it. I recognize that this is probably not very helpful as to what the problem is, but tis what I have.

@wraith1995 wraith1995 changed the title Bug in EigenValue calculation Odd EigenValue calculation Feb 29, 2016
@wraith1995 wraith1995 changed the title Odd EigenValue calculation Odd EigenVector calculation Feb 29, 2016
@lvandeve
Copy link
Owner

lvandeve commented Mar 1, 2016

Hi, thanks for the report, this is very useful.

It seems to be a numerical problem. One of the eigenvalues became 4.4e-16 instead of 0.
That is already a numerical problem on its own, but within the 1e-15 machine precision, so that in itself is not a bug.

However, that value then caused the SVD in the solve function used to find the eigenvectors to return a much more incorrect value, resulting in that -50, and that is of course a bug.

So I tried a quick fix now, in which before solving the eigenvectors, it sets eigenvalues that are near 0, to 0.

This is a very hacky and unstable fix, it would require much more numerical care and investigation to fix for sure, but I hope it helps at least in cases like this.

@minkkilaukku
Copy link

Hi, I'm also getting a weird output for this:

Jmat.eig([[1,-0.3,-0.5],[-0.3,1,-0.6],[-0.5,-0.6,1]]).l.toString()
"[[1], [1], [1]]"

If I change some value a tiny bit it becomes correct:

Jmat.eig([[1.000001,-0.3,-0.5],[-0.3,1,-0.6],[-0.5,-0.6,1]]).l.toString()
"[[1.6506594099893412], [1.293122146749505], [0.05621944326115451]]"

@lvandeve
Copy link
Owner

Thanks minkkilaukku! I found and fixed the issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants