本文整理汇总了C#中MathNet.Numerics.LinearAlgebra.Double.SparseMatrix.SolveIterative方法的典型用法代码示例。如果您正苦于以下问题:C# SparseMatrix.SolveIterative方法的具体用法?C# SparseMatrix.SolveIterative怎么用?C# SparseMatrix.SolveIterative使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MathNet.Numerics.LinearAlgebra.Double.SparseMatrix
的用法示例。
在下文中一共展示了SparseMatrix.SolveIterative方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SolveLongMatrixThrowsArgumentException
public void SolveLongMatrixThrowsArgumentException()
{
var matrix = new SparseMatrix(3, 2);
var input = new DenseVector(3);
var solver = new MlkBiCgStab();
Assert.That(() => matrix.SolveIterative(input, solver), Throws.ArgumentException);
}
示例2: SolveWideMatrixThrowsArgumentException
public void SolveWideMatrixThrowsArgumentException()
{
var matrix = new SparseMatrix(2, 3);
var input = new DenseVector(2);
var solver = new TFQMR();
Assert.That(() => matrix.SolveIterative(input, solver), Throws.ArgumentException);
}
示例3: SolveLongMatrixThrowsArgumentException
public void SolveLongMatrixThrowsArgumentException()
{
var matrix = new SparseMatrix(3, 2);
var input = new DenseVector(3);
var solver = new GpBiCg();
Assert.Throws<ArgumentException>(() => matrix.SolveIterative(input, solver));
}
示例4: SolveWideMatrixThrowsArgumentException
public void SolveWideMatrixThrowsArgumentException()
{
var matrix = new SparseMatrix(2, 3);
var input = new DenseVector(2);
var solver = new MlkBiCgStab();
Assert.Throws<ArgumentException>(() => matrix.SolveIterative(input, solver));
}
示例5: SolvePoissonMatrixAndBackMultiply
public void SolvePoissonMatrixAndBackMultiply()
{
// Create the matrix
var matrix = new SparseMatrix(100);
// Assemble the matrix. We assume we're solving the Poisson equation
// on a rectangular 10 x 10 grid
const int GridSize = 10;
// The pattern is:
// 0 .... 0 -1 0 0 0 0 0 0 0 0 -1 4 -1 0 0 0 0 0 0 0 0 -1 0 0 ... 0
for (var i = 0; i < matrix.RowCount; i++)
{
// Insert the first set of -1's
if (i > (GridSize - 1))
{
matrix[i, i - GridSize] = -1;
}
// Insert the second set of -1's
if (i > 0)
{
matrix[i, i - 1] = -1;
}
// Insert the centerline values
matrix[i, i] = 4;
// Insert the first trailing set of -1's
if (i < matrix.RowCount - 1)
{
matrix[i, i + 1] = -1;
}
// Insert the second trailing set of -1's
if (i < matrix.RowCount - GridSize)
{
matrix[i, i + GridSize] = -1;
}
}
// Create the y vector
var y = DenseVector.Create(matrix.RowCount, i => 1);
// Create an iteration monitor which will keep track of iterative convergence
var monitor = new Iterator<double>(
new IterationCountStopCriterium<double>(MaximumIterations),
new ResidualStopCriterium<double>(ConvergenceBoundary),
new DivergenceStopCriterium<double>(),
new FailureStopCriterium<double>());
var solver = new GpBiCg();
// Solve equation Ax = y
var x = matrix.SolveIterative(y, solver, monitor);
// Now compare the results
Assert.IsNotNull(x, "#02");
Assert.AreEqual(y.Count, x.Count, "#03");
// Back multiply the vector
var z = matrix.Multiply(x);
// Check that the solution converged
Assert.IsTrue(monitor.Status == IterationStatus.Converged, "#04");
// Now compare the vectors
for (var i = 0; i < y.Count; i++)
{
Assert.GreaterOrEqual(ConvergenceBoundary, Math.Abs(y[i] - z[i]), "#05-" + i);
}
}