int main(int argc, char *argv[]) { int info; int n = 6; if (argc > 1) n = boost::lexical_cast<int>(argv[1]); std::cout << "n = " << n << std::endl; // generate symmmetric random martix matrix_t mat = matrix_t::Random(n, n); mat += mat.transpose().eval(); // eval() is required to avoid aliasing issue std::cout << "Input random matrix A:\n" << mat << std::endl; // diagonalization vector_t w(n); matrix_t v = mat; // v will be overwritten by eigenvectors info = LAPACKE_dsyev(LAPACK_COL_MAJOR, 'V', 'U', n, &v(0, 0), n, &w(0)); std::cout << "Eigenvalues:\n" << w << std::endl; std::cout << "Eigenvectors:\n" << v << std::endl; // check correctness of diagonalization matrix_t wmat = matrix_t::Zero(n, n); for (int i = 0; i < n; ++i) wmat(i, i) = w(i); matrix_t check = v.transpose() * mat * v; std::cout << "Vt * A * V:\n" << check << std::endl; std::cout << "| W - Vt * A * V | = " << (wmat - check).norm() << std::endl; }
double Simplex::getVolume() const { // See http://www.math.niu.edu/~rusin/known-math/97/volumes.polyh double res = 0.0; if (mndims == 0) return res; if (mnpdims == 0) return res; // all vertices have been set std::vector< std::vector<double> > wmat(mndims, std::vector<double>(mnpdims)); for (size_t jcol = 0; jcol < mnpdims; ++jcol) { for (size_t irow = 0; irow < mndims; ++irow) { wmat[irow][jcol] = mvertices[jcol + 1][irow] - mvertices[0][irow]; } } // transpose(wmat) * wmat std::vector<double> wmatTDotWmat(mnpdims * mnpdims, 0.0); for (size_t jcol = 0; jcol < mnpdims; ++jcol) { for (size_t irow = 0; irow < mnpdims; ++irow) { size_t k = irow + mnpdims*jcol; for (size_t el = 0; el < mndims; ++el) { wmatTDotWmat[k] += wmat[el][irow] * wmat[el][jcol]; } } } double det = this->getDeterminant(wmatTDotWmat); res = det / factorial(mnpdims); return res; }