本文整理汇总了C#中MathNet.Numerics.LinearAlgebra.Complex.DenseVector类的典型用法代码示例。如果您正苦于以下问题:C# DenseVector类的具体用法?C# DenseVector怎么用?C# DenseVector使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DenseVector类属于MathNet.Numerics.LinearAlgebra.Complex命名空间,在下文中一共展示了DenseVector类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HeapSortWithDecreasingDoubleArray
public void HeapSortWithDecreasingDoubleArray()
{
var sortedIndices = new int[10];
Vector<Complex> values = new DenseVector(10);
values[0] = 9;
values[1] = 8;
values[2] = 7;
values[3] = 6;
values[4] = 5;
values[5] = 4;
values[6] = 3;
values[7] = 2;
values[8] = 1;
values[9] = 0;
for (var i = 0; i < sortedIndices.Length; i++)
{
sortedIndices[i] = i;
}
ILUTPElementSorter.SortDoubleIndicesDecreasing(0, sortedIndices.Length - 1, sortedIndices, values);
for (var i = 0; i < sortedIndices.Length; i++)
{
Assert.AreEqual(i, sortedIndices[i], "#01-" + i);
}
}
示例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 BiCgStab();
Assert.That(() => matrix.SolveIterative(input, solver), Throws.ArgumentException);
}
示例4: SolveLongMatrixThrowsArgumentException
public void SolveLongMatrixThrowsArgumentException()
{
var matrix = new SparseMatrix(3, 2);
var input = new DenseVector(3);
var solver = new TFQMR();
Assert.Throws<ArgumentException>(() => matrix.SolveIterative(input, solver));
}
示例5: SolveWideMatrixThrowsArgumentException
public void SolveWideMatrixThrowsArgumentException()
{
var matrix = new SparseMatrix(2, 3);
var input = new DenseVector(2);
var solver = new GpBiCg();
Assert.Throws<ArgumentException>(() => matrix.SolveIterative(input, solver));
}
示例6: CreateStandardBcVector
/// <summary>
/// Create standard vector.
/// </summary>
/// <param name="size">Size of the vector.</param>
/// <returns>New vector.</returns>
protected DenseVector CreateStandardBcVector(int size)
{
var vector = new DenseVector(size);
for (var i = 0; i < size; i++)
{
vector[i] = i + 1;
}
return vector;
}
示例7: CreateVector
/// <summary>
/// Creates a new instance of the Vector class.
/// </summary>
/// <param name="data">The array to create this vector from.</param>
/// <returns>The new <c>Vector</c>.</returns>
protected override Vector<Complex> CreateVector(IList<Complex> data)
{
var vector = new DenseVector(data.Count);
for (var index = 0; index < data.Count; index++)
{
vector[index] = data[index];
}
return vector;
}
示例8: DetermineStatus
public void DetermineStatus()
{
var criterium = new FailureStopCriterium();
Assert.IsNotNull(criterium, "There should be a criterium");
var solution = new DenseVector(new[] {new Complex(3.0, 0), new Complex(2.0, 0), new Complex(1, 0)});
var source = new DenseVector(new[] {new Complex(1001.0, 0), Complex.Zero, new Complex(2003.0, 0)});
var residual = new DenseVector(new[] {new Complex(1.0, 0), new Complex(2.0, 0), new Complex(3, 0)});
var status = criterium.DetermineStatus(5, solution, source, residual);
Assert.AreEqual(IterationStatus.Continue, status, "Should be running");
}
示例9: CanAddTwoDenseVectorsUsingOperator
public void CanAddTwoDenseVectorsUsingOperator()
{
var vector = new DenseVector(Data);
var other = new DenseVector(Data);
var result = vector + other;
CollectionAssert.AreEqual(Data, vector, "Making sure the original vector wasn't modified.");
CollectionAssert.AreEqual(Data, other, "Making sure the original vector wasn't modified.");
for (var i = 0; i < Data.Length; i++)
{
Assert.AreEqual(Data[i]*2.0, result[i]);
}
}
示例10: ApproximateReturningOldVector
public void ApproximateReturningOldVector()
{
const int Size = 10;
var newMatrix = CreateUnitMatrix(Size);
var vector = CreateStandardBcVector(Size);
var preconditioner = CreatePreconditioner();
preconditioner.Initialize(newMatrix);
var result = new DenseVector(vector.Count);
preconditioner.Approximate(vector, result);
CheckResult(preconditioner, newMatrix, vector, result);
}
示例11: CanCreateDenseVectorFromArray
public void CanCreateDenseVectorFromArray()
{
var data = new Complex[Data.Length];
Array.Copy(Data, data, Data.Length);
var vector = new DenseVector(data);
for (var i = 0; i < data.Length; i++)
{
Assert.AreEqual(data[i], vector[i]);
}
vector[0] = new Complex(10.0, 1);
Assert.AreEqual(new Complex(10.0, 1), data[0]);
}
示例12: CanMultiplyWithVector
public void CanMultiplyWithVector()
{
var matrix = TestMatrices["Singular3x3"];
var x = new DenseVector(new[] { new Complex(1, 1), new Complex(2, 1), new Complex(3, 1) });
var y = matrix * x;
Assert.AreEqual(matrix.RowCount, y.Count);
for (var i = 0; i < matrix.RowCount; i++)
{
var ar = matrix.Row(i);
var dot = ar * x;
Assert.AreEqual(dot, y[i]);
}
}
示例13: CheckResult
/// <summary>
/// Check the result.
/// </summary>
/// <param name="preconditioner">Specific preconditioner.</param>
/// <param name="matrix">Source matrix.</param>
/// <param name="vector">Initial vector.</param>
/// <param name="result">Result vector.</param>
protected override void CheckResult(IPreconditioner<Complex> preconditioner, SparseMatrix matrix, Vector<Complex> vector, Vector<Complex> result)
{
Assert.AreEqual(typeof(Diagonal), preconditioner.GetType(), "#01");
// Compute M * result = product
// compare vector and product. Should be equal
var product = new DenseVector(result.Count);
matrix.Multiply(result, product);
for (var i = 0; i < product.Count; i++)
{
Assert.IsTrue(vector[i].Real.AlmostEqual(product[i].Real, -Epsilon.Magnitude()), "#02-" + i);
Assert.IsTrue(vector[i].Imaginary.AlmostEqual(product[i].Imaginary, -Epsilon.Magnitude()), "#03-" + i);
}
}
示例14: CanSolveForRandomVectorWhenResultVectorGiven
public void CanSolveForRandomVectorWhenResultVectorGiven(int row, int column)
{
var matrixA = MatrixLoader.GenerateRandomDenseMatrix(row, column);
var matrixACopy = matrixA.Clone();
var factorSvd = matrixA.Svd();
var vectorb = MatrixLoader.GenerateRandomDenseVector(row);
var vectorbCopy = vectorb.Clone();
var resultx = new DenseVector(column);
factorSvd.Solve(vectorb, resultx);
var matrixBReconstruct = matrixA*resultx;
// Check the reconstruction.
for (var i = 0; i < vectorb.Count; i++)
{
AssertHelpers.AlmostEqual(vectorb[i], matrixBReconstruct[i], 9);
}
// Make sure A didn't change.
for (var i = 0; i < matrixA.RowCount; i++)
{
for (var j = 0; j < matrixA.ColumnCount; j++)
{
Assert.AreEqual(matrixACopy[i, j], matrixA[i, j]);
}
}
// Make sure b didn't change.
for (var i = 0; i < vectorb.Count; i++)
{
Assert.AreEqual(vectorbCopy[i], vectorb[i]);
}
}
示例15: CanCallUnaryNegationOperatorOnDenseVector
public void CanCallUnaryNegationOperatorOnDenseVector()
{
var vector = new DenseVector(Data);
var other = -vector;
for (var i = 0; i < Data.Length; i++)
{
Assert.AreEqual(-Data[i], other[i]);
}
}