Matlab Codgen eig() function - strange behaviour

烂漫一生 提交于 2019-12-06 11:44:32
Daniel

There is not only one valid answer for a eigenvalue problem. Whenever dealing with such cases, best practice is to use or define a canonical form to convert equivalent answers to identical answers. To convert any answer into such a canonical form, I would apply the following steps:

  1. Normalize all eigenvectors to length 1 (example: [-0.4472,-0.4472,-0.4472,0.4472,0.4472]' instead of [-1,-1,-1,1,1]'). Could be achieved using b=bsxfun(@rdivide,b,sqrt(sum(b.^2,1)))
  2. For each eigenvectors with a negative value in the first component, take the negative value. (example: [0.4472,0.4472,0.4472,-0.4472,-0.4472]' instead of [-0.4472,-0.4472,-0.4472,0.4472,0.4472]'). Could be achieved using b=bsxfun(@times,sign(b(1,:)),b)
  3. Sort eigenvectors and eigenvalues in ascending order of the eigenvalues. Could be achieved using this code

Please note that this is just one canonical form, not the canonical form. There might be canonical forms established but I have not found any reference so I basically put together what we discussed above to define a canonical form. Mathematically, applying such a canonical form results in a unique solution. In practice you will observe minor differences because of floating point precision errors.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!