[vtkusers] Jacobi eigenvectors incorrect?
David Doria
daviddoria+vtk at gmail.com
Fri Oct 30 09:45:52 EDT 2009
On Fri, Oct 30, 2009 at 9:05 AM, Bryn Lloyd <blloyd at vision.ee.ethz.ch> wrote:
> Hi David,
>
> I get the same result, using my test code.
>
> Matlab:
> a = [1,2,3; 2,5,9; 3,9,8]
> [v,w] = eig(a)
>
> v =
> 0.1372 0.9644 0.2259
> 0.7382 -0.2516 0.6259
> -0.6605 -0.0809 0.7464
>
>
> w =
> -2.6814 0 0
> 0 0.2266 0
> 0 0 16.4547
>
>
> C++:
> 16.4547 0.225898 -0.964436 0.137232
> 0.226646 0.625927 0.251645 0.738167
> -2.68139 0.746449 0.0808535 -0.660513
>
> Both are the same, except the sign difference for (ordered) Eigenvector 2.
> Note that Matlab does not order them.
>
> /Bryn
Bryn,
I also get the correct result with your code, not sure what I was
doing wrong, but I'll just use your way. Bill/Bryn - can this code
that Bryn has written be turned into a vtkMatrix class? I think it is
insane for users to have to write this:
template<class TReal>
TReal **create_matrix(long nrow, long ncol) {
typedef TReal* TRealPointer;
TReal **m = new TRealPointer[nrow];
TReal* block = (TReal*)calloc(nrow*ncol, sizeof(TReal));
m[0] = block;
for ( int row = 1; row < nrow; ++row ) {
m[ row ] = &block[ row * ncol ];
}
return m;
}
in order to get eigen vectors of a matrix.
Thanks,
David
More information about the vtkusers
mailing list