本文整理汇总了C++中MyVector::getSize方法的典型用法代码示例。如果您正苦于以下问题:C++ MyVector::getSize方法的具体用法?C++ MyVector::getSize怎么用?C++ MyVector::getSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MyVector
的用法示例。
在下文中一共展示了MyVector::getSize方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: IncompatibleMatrixSizes
MyVector<T>
TridiagonalMatrix<T>::operator*(const MyVector<T>& vec) const
{
if(size != vec.getSize())
{
throw typename Matrix<T>::
IncompatibleMatrixSizes(size, size,
vec.getSize(), vec.getSize());
}
MyVector<T> rv(size);
if(size == 1)
{
rv[0] = getNonZeroElement(0,0) * vec[0];
}
else
{
// add the appropriate sums from the first column of the matrix
rv[0] += getNonZeroElement(0, 0) * vec[0];
rv[1] += getNonZeroElement(1, 0) * vec[0];
// add the appropriate sums from the second through n-1 columns
// of the matrix
for(size_t j = 1; j < size - 1; ++j)
{
for(size_t i = j - 1; i <= j + 1; ++i)
{
rv[i] += getNonZeroElement(i, j) * vec[j];
}
}
// add the appropriate sums from the last column of the matrix
rv[size - 2] +=
getNonZeroElement(size - 2, size - 1) * vec[size - 1];
rv[size - 1] +=
getNonZeroElement(size - 1, size - 1) * vec[size - 1];
}
return rv;
}
示例2: result
MyVector<T>
DenseMatrix<T>::operator*(const MyVector<T>& v) const
{
if(numCols != v.getSize())
{
throw typename Matrix<T>::IncompatibleMatrixSizes
(numRows, numCols, v.getSize(), 1);
// vectors always have one column
}
// again, go with the column number in the outer loop because
// matrices are stored in column major order
MyVector<T> result(numRows);
for(size_t j = 0; j < numCols; ++j)
{
for(size_t i = 0; i < numRows; ++i)
{
result[i] += a(i, j) * v[j];
}
}
return result;
}
示例3: numRows
DenseMatrix<T>::DenseMatrix(const MyVector<T>& v)
: numRows(v.getSize()), numCols((numRows != 0)?1:0)
{
if(numRows == 0)
{
data = NULL;
}
else
{
data = new T[numRows];
for(size_t i = 0; i < numRows; ++i)
{
data[i] = v[i];
}
}
}
示例4: bPermutation
MyVector<T>
LUDecompositionSolver<T>::
operator()(const typename LUDecomposition<T>::Solution& decomposition,
const MyVector<T>& b) const
{
const LowerTriangularMatrix<T>& L = decomposition.L();
const UpperTriangularMatrix<T>& U = decomposition.U();
const typename LUDecomposition<T>::OrderType& order =
decomposition.orderVector();
if(L.getNumRows() != b.getSize())
{
throw typename LUDecompositionSolver<T>::IncompatibleMatrixAndVector();
}
MyVector<T> bPermutation(b);
for(size_t i = 1; i < L.getNumRows(); ++i)
{
T sum = bPermutation[order[i]];
for(size_t j = 0; j < i; ++j)
{
sum -= L[order[i]][j] * bPermutation[order[j]];
}
bPermutation[order[i]] = sum;
}
MyVector<T> x(U.getNumCols());
const size_t lastRow = x.getSize() - 1;
x[lastRow] = bPermutation[order[lastRow]] / U[order[lastRow]][lastRow];
for(int i = L.getNumRows() - 1; i >= 0; --i)
{
T sum = 0;
for(size_t j = i+1; j < L.getNumRows(); ++j)
{
sum += U[order[i]][j]*x[j];
}
x[i] = (bPermutation[order[i]] - sum) / U[order[i]][i];
}
return x;
}