-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Closed
Description
The documentation example has this line:
const ans = math.eigs(H) // returns {values: [E1,E2...sorted], vectors: [v1,v2.... corresponding vectors]}Which tells us mathematically that:
H * v1 = E1 * v1
However, this doesn't actually work:
>>> H = [[1,0,0],[0,1,0],[0,0,-1]]; e =math.eigs(H)
>>> math.multiply(H,e.vectors[0])
[0,1,0]
>>> math.multiply(e.values[0],e.vectors[0])
[-0,-1,-0]These should give the same result! In this particular case, e.vectors[1] goes with e.values[0]:
>>> math.multiply(H,e.vectors[1])
[0,0,-1]
>>> math.multiply(e.values[0],e.vectors[1])
[-0,-0,-1]The reason is that the eigenvalues are sorted, but the eigenvectors are still in the original, unsorted order, and thus not "corresponding" as implied by the documentation.
Slow workaround:
var e = math.eigs(H)
// Sort in place
e.vectors.sort((v,w) => {
// Compare by eigenvalues
return math.dot(math.multiply(H,v),v) - math.dot(math.multiply(H,w),w)
})Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels