本文整理汇总了C++中MatrixDouble::GetCols方法的典型用法代码示例。如果您正苦于以下问题:C++ MatrixDouble::GetCols方法的具体用法?C++ MatrixDouble::GetCols怎么用?C++ MatrixDouble::GetCols使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MatrixDouble
的用法示例。
在下文中一共展示了MatrixDouble::GetCols方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Cramer
/*!
* Solve linear system using Cramer procedure
*
* \throw ExceptionDimension incompatible matrix dimensions
* \throw ExceptionRuntime Equation has either no solution or an infinity of solutions
*
* \param[in] Coefficients matrix of equations' coefficients
* \param[in] ConstantTerms column matrix of constant term
*
* \return solutions packed in a column matrix (SMatrixDouble)
*/
MatrixDouble LinearSystem::Cramer(const SquareMatrixDouble &Coefficients, const MatrixDouble &ConstantTerms)
{
size_t n = Coefficients.GetRows();
if ((ConstantTerms.GetRows() != n) || (ConstantTerms.GetCols() != 1))
{
throw ExceptionDimension(StringUTF8("LinearEquationsSystem::CramerSolver("
"const SquareMatrixDouble *Coefficients, const MatrixDouble *ConstantTerms): ") +
_("invalid or incompatible matrix dimensions"));
}
else
{
double D = Coefficients.Determinant();
if (D == 0.0)
{
throw ExceptionRuntime(_("Equation has either no solution or an infinity of solutions."));
}
MatrixDouble Solutions(n, 1, 0.0);
for (size_t k = 0; k < n; k++)
{
SquareMatrixDouble Mk(Coefficients);
for (size_t r = 0; r < n; r++)
{
Mk.At(r, k) = ConstantTerms.At(r, 0);
}
double Dk = Mk.Determinant();
Solutions.At(k, 0) = Dk / D;
}
return Solutions;
}
}