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


C++ MatrixDouble::At方法代码示例

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


在下文中一共展示了MatrixDouble::At方法的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;
	}
}
开发者ID:Liris-Pleiad,项目名称:libcrn,代码行数:49,代码来源:CRNEquationSolver.cpp


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