当前位置: 首页>>代码示例>>C++>>正文


C++ SquareMatrix::Inverse方法代码示例

本文整理汇总了C++中SquareMatrix::Inverse方法的典型用法代码示例。如果您正苦于以下问题:C++ SquareMatrix::Inverse方法的具体用法?C++ SquareMatrix::Inverse怎么用?C++ SquareMatrix::Inverse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SquareMatrix的用法示例。


在下文中一共展示了SquareMatrix::Inverse方法的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;
    }
开发者ID:Linhua-Sun,项目名称:phycas,代码行数:54,代码来源:square_matrix.cpp


注:本文中的SquareMatrix::Inverse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。