[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Toon-members] TooN SymEigen.h test/eigen-sqrt.cc
From: |
Damian Eads |
Subject: |
[Toon-members] TooN SymEigen.h test/eigen-sqrt.cc |
Date: |
Fri, 28 Aug 2009 01:14:23 +0000 |
CVSROOT: /sources/toon
Module name: TooN
Changes by: Damian Eads <eads> 09/08/28 01:14:23
Modified files:
. : SymEigen.h
Added files:
test : eigen-sqrt.cc
Log message:
Updated example to include inverse square root. Put it in a test source
file.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/TooN/SymEigen.h?cvsroot=toon&r1=1.23&r2=1.24
http://cvs.savannah.gnu.org/viewcvs/TooN/test/eigen-sqrt.cc?cvsroot=toon&rev=1.1
Patches:
Index: SymEigen.h
===================================================================
RCS file: /sources/toon/TooN/SymEigen.h,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -b -r1.23 -r1.24
--- SymEigen.h 27 Aug 2009 21:06:05 -0000 1.23
+++ SymEigen.h 28 Aug 2009 01:14:22 -0000 1.24
@@ -129,20 +129,37 @@
are the eigenvalues of \f$M\f$. These quantities are often of use directly,
and can
be obtained as follows:
@code
+// construct M
Matrix<3> M(3,3);
M[0]=makeVector(4,0,2);
M[1]=makeVector(0,5,3);
M[2]=makeVector(2,3,6);
+
// create the eigen decomposition of M
SymEigen<3> eigM(M);
+cout << "A=" << M << endl;
+cout << "(E,v)=eig(A)" << endl;
// print the smallest eigenvalue
-cout << eigM.get_evalues()[0] << endl;
+cout << "v[0]=" << eigM.get_evalues()[0] << endl;
// print the associated eigenvector
-cout << eigM.get_evectors()[0] << endl;
+cout << "E[0]=" << eigM.get_evectors()[0] << endl;
address@hidden
+
+Further, provided the eigenvalues are nonnegative, the square root of
+a matrix and its inverse can also be obtained,
address@hidden
// print the square root of the matrix.
-cout << eigM.get_sqrtm() << endl;
+cout << "R=sqrtm(A)=" << eigM.get_sqrtm() << endl;
// print the square root of the matrix squared.
-cout << eigM.get_sqrtm().T() * eigM.get_sqrtm() << endl;
+cout << "(should equal A), R^T*R="
+ << eigM.get_sqrtm().T() * eigM.get_sqrtm() << endl;
+// print the inverse of the matrix.
+cout << "A^-1=" << eigM.get_pinv() << endl;
+// print the inverse square root of the matrix.
+cout << "C=isqrtm(A)=" << eigM.get_isqrtm() << endl;
+// print the inverse square root of the matrix squared.
+cout << "(should equal A^-1), C^T*C="
+ << eigM.get_isqrtm().T() * eigM.get_isqrtm() << endl;
@endcode
This decomposition is very similar to the SVD (q.v.), and can be used to solve
Index: test/eigen-sqrt.cc
===================================================================
RCS file: test/eigen-sqrt.cc
diff -N test/eigen-sqrt.cc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ test/eigen-sqrt.cc 28 Aug 2009 01:14:23 -0000 1.1
@@ -0,0 +1,39 @@
+#include <iostream>
+#include <TooN/TooN.h>
+#include <TooN/SymEigen.h>
+
+using namespace std;
+using namespace TooN;
+
+int main() {
+ // construct M
+ double d1[][3] = {{1,2,3},{2,5,6},{3,6,7}};
+ Matrix<3> M(3,3);
+ M[0]=makeVector(4,0,2);
+ M[1]=makeVector(0,5,3);
+ M[2]=makeVector(2,3,6);
+
+ Vector<3> dg(makeVector(2,4,9));
+ // create the eigen decomposition of M
+ SymEigen<3> eigM(M);
+ cout << "A=" << M << endl;
+ cout << "(E,v)=eig(A)" << endl;
+ // print the smallest eigenvalue
+ cout << "v[0]=" << eigM.get_evalues()[0] << endl;
+ // print the associated eigenvector
+ cout << "E[0]=" << eigM.get_evectors()[0] << endl;
+ // print the square root of the matrix.
+ cout << "R=sqrtm(A)=" << eigM.get_sqrtm() << endl;
+ // print the square root of the matrix squared.
+ cout << "(should equal A), R^T*R="
+ << eigM.get_sqrtm().T() * eigM.get_sqrtm() << endl;
+ // print the inverse of the matrix.
+ cout << "A^-1=" << eigM.get_pinv() << endl;
+ // print the inverse square root of the matrix.
+ cout << "C=isqrtm(A)=" << eigM.get_isqrtm() << endl;
+ // print the inverse square root of the matrix squared.
+ cout << "(should equal A^-1), C^T*C="
+ << eigM.get_isqrtm().T() * eigM.get_isqrtm() << endl;
+
+ return 0;
+}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Toon-members] TooN SymEigen.h test/eigen-sqrt.cc,
Damian Eads <=