本文整理汇总了C++中AbstractMatrix::getColumn方法的典型用法代码示例。如果您正苦于以下问题:C++ AbstractMatrix::getColumn方法的具体用法?C++ AbstractMatrix::getColumn怎么用?C++ AbstractMatrix::getColumn使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AbstractMatrix
的用法示例。
在下文中一共展示了AbstractMatrix::getColumn方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: domain_error
void QRDecomposition<T>::operator()(const AbstractMatrix<T>& aMatrix)
{
q = GenericMatrix<T>(aMatrix.rows());
r = TriangularMatrix<T>(aMatrix.rows(), TRIANGLE_TYPE::UPPER);
T normResult;
TwoNorm<T> norm;
/*for(int i = 0; i < aMatrix.rows(); i++)
{
for(int j = 0; j < aMatrix.rows(); j++)
{
q[i][j] = 0;
r[i][j] = 0;
//q(i, j) = 0;
//r(i, j) = 0;
}
}*/
int rows = static_cast<int>(aMatrix.rows());
for(int i = 0; i < rows; i++)
{
if(i == 0)
{
normResult = norm(aMatrix.getColumn(0));
if(normResult == 0)
{
throw std::domain_error("Error in QRDecomposition: Attempted division by zero");
}
for(int j = 0; j < rows; j++)
{
q[j][0] = aMatrix[j][0] * (1 / normResult);
}
}
else
{
AlgebraVector<T> temp(aMatrix[0]);
temp = r[0][i] * q.getColumn(0);
//temp = r(0, i) * q.getColumn(0);
for(int k = 1; k < i; k++)
{
temp += r[k][i] * q.getColumn(k);
//temp += r(k, i) * q.getColumn(k);
}
temp = aMatrix.getColumn(i) - temp;
r[i][i] = norm(temp);
//r(i, i) = norm(temp);
//if(r(i, i) == 0)
if(r[i][i] == 0)
{
throw std::domain_error("QRDecomposition: Attempted division by zero");
}
for(int j = 0; j < rows; j++)
{
q[j][i] = (1 / r[i][i]) * temp[j];
//q(j, i) = (1 / r(i, i)) * temp[j];
}
}
for(int j = 0; j < rows; j++)
{
r[i][j] = aMatrix.getColumn(j) * q.getColumn(i);
//r(i, j) = aMatrix.getColumn(j) * q.getColumn(i);
}
}
}
示例2: domain_error
void QRDecomposition<T>::operator()(const AbstractMatrix<T>& aMatrix)
{
q = DenseMatrix<T>(aMatrix.numRows(), aMatrix.numRows());
r = UpperTriangularMatrix<T>(aMatrix.numRows());
T normResult;
TwoNorm<T> norm;
for(int i = 0; i < aMatrix.numRows(); i++)
{
for(int j = 0; j < aMatrix.numRows(); j++)
{
q(i, j) = 0;
r(i, j) = 0;
}
}
for(int i = 0; i < aMatrix.numRows(); i++)
{
if(i == 0)
{
normResult = norm(aMatrix.getColumn(0));
if(normResult == 0)
{
throw std::domain_error("Error in QRDecomposition: Attempted division by zero");
}
for(int j = 0; j < aMatrix.numRows(); j++)
{
q(j, 0) = aMatrix(j, 0) * (1 / normResult);
}
}
else
{
Vector<T> temp(aMatrix.numRows());
temp = r(0, i) * q.getColumn(0);
for(int k = 1; k < i; k++)
{
temp += r(k, i) * q.getColumn(k);
}
temp = aMatrix.getColumn(i) - temp;
r(i, i) = norm(temp);
if(r(i, i) == 0)
{
throw std::domain_error("QRDecomposition: Attempted division by zero");
}
for(int j = 0; j < aMatrix.numRows(); j++)
{
q(j, i) = (1 / r(i, i)) * temp[j];
}
}
for(int j = 0; j < aMatrix.numRows(); j++)
{
r(i, j) = aMatrix.getColumn(j) * q.getColumn(i);
}
}
}