本文整理汇总了C++中SquareMatrix::RightMultiplyMatrix方法的典型用法代码示例。如果您正苦于以下问题:C++ SquareMatrix::RightMultiplyMatrix方法的具体用法?C++ SquareMatrix::RightMultiplyMatrix怎么用?C++ SquareMatrix::RightMultiplyMatrix使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SquareMatrix
的用法示例。
在下文中一共展示了SquareMatrix::RightMultiplyMatrix方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SquareMatrix
/*----------------------------------------------------------------------------------------------------------------------
| Creates and returns a matrix that represents this matrix raised to the power `p'.
*/
SquareMatrix * SquareMatrix::Power(
double p) const /**< the power to which this matrix should be raised */
{
PHYCAS_ASSERT(dim > 0);
//PHYCAS_ASSERT(p > 0.0);
double * fv = new double[dim];
double * w = new double[dim];
double ** a = this->GetMatrixAsRawPointer();
SquareMatrix * Z = new SquareMatrix(dim, 0.0);
double ** z = Z->GetMatrixAsRawPointer();
// Calculate eigenvalues (w) and eigenvectors (z)
// int n input: the order of the matrix a
// double **a input: the real symmetric matrix
// double *fv input: temporary storage array of at least n elements
// double **z output: the eigenvectors
// double *w output: the eigenvalues in ascending order
int err_code = EigenRealSymmetric(dim, a, w, z, fv);
if (err_code != 0)
{
delete Z;
delete [] fv;
delete [] w;
return 0;
}
SquareMatrix * Zinv = Z->Inverse();
SquareMatrix * Lp = new SquareMatrix(dim, 0.0);
// create diagonal matrix of scaled eigenvalues
for (unsigned i = 0; i < dim; ++i)
{
double v = pow(w[i],p);
Lp->SetElement(i, i, v);
}
// Zinv * A * Z = L
// A = Z * L * Zinv
// A^p = Z * L^p * Zinv
SquareMatrix * ZLp = Z->RightMultiplyMatrix(*Lp);
SquareMatrix * Ap = ZLp->RightMultiplyMatrix(*Zinv);
delete Z;
delete Zinv;
delete Lp;
delete ZLp;
delete [] fv;
delete [] w;
return Ap;
}