本文整理汇总了C#中System.Numerics.Vector.Norm方法的典型用法代码示例。如果您正苦于以下问题:C# Vector.Norm方法的具体用法?C# Vector.Norm怎么用?C# Vector.Norm使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Numerics.Vector
的用法示例。
在下文中一共展示了Vector.Norm方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Solve
/// <summary>
/// Solves the matrix equation Ax = b, where A is the coefficient matrix, b is the
/// solution vector and x is the unknown vector.
/// </summary>
/// <param name="matrix">The coefficient matrix, <c>A</c>.</param>
/// <param name="input">The solution vector, <c>b</c></param>
/// <param name="result">The result vector, <c>x</c></param>
public void Solve(Matrix matrix, Vector input, Vector result)
{
// If we were stopped before, we are no longer
// We're doing this at the start of the method to ensure
// that we can use these fields immediately.
_hasBeenStopped = false;
// Error checks
if (matrix == null)
{
throw new ArgumentNullException("matrix");
}
if (matrix.RowCount != matrix.ColumnCount)
{
throw new ArgumentException(Resources.ArgumentMatrixSquare, "matrix");
}
if (input == null)
{
throw new ArgumentNullException("input");
}
if (result == null)
{
throw new ArgumentNullException("result");
}
if (input.Count != matrix.RowCount || result.Count != input.Count)
{
throw Matrix.DimensionsDontMatch<ArgumentException>(matrix, input, result);
}
// Initialize the solver fields
// Set the convergence monitor
if (_iterator == null)
{
_iterator = Iterator.CreateDefault();
}
if (_preconditioner == null)
{
_preconditioner = new UnitPreconditioner();
}
_preconditioner.Initialize(matrix);
var d = new DenseVector(input.Count);
var r = DenseVector.OfVector(input);
var uodd = new DenseVector(input.Count);
var ueven = new DenseVector(input.Count);
var v = new DenseVector(input.Count);
var pseudoResiduals = DenseVector.OfVector(input);
var x = new DenseVector(input.Count);
var yodd = new DenseVector(input.Count);
var yeven = DenseVector.OfVector(input);
// Temp vectors
var temp = new DenseVector(input.Count);
var temp1 = new DenseVector(input.Count);
var temp2 = new DenseVector(input.Count);
// Initialize
var startNorm = input.Norm(2);
// Define the scalars
Complex alpha = 0;
Complex eta = 0;
double theta = 0;
var tau = startNorm.Real;
Complex rho = tau*tau;
// Calculate the initial values for v
// M temp = yEven
_preconditioner.Approximate(yeven, temp);
// v = A temp
matrix.Multiply(temp, v);
// Set uOdd
v.CopyTo(ueven);
// Start the iteration
var iterationNumber = 0;
while (ShouldContinue(iterationNumber, result, input, pseudoResiduals))
{
// First part of the step, the even bit
if (IsEven(iterationNumber))
{
//.........这里部分代码省略.........