本文整理汇总了C#中System.Matrix.ValidateIsSymmetric方法的典型用法代码示例。如果您正苦于以下问题:C# Matrix.ValidateIsSymmetric方法的具体用法?C# Matrix.ValidateIsSymmetric怎么用?C# Matrix.ValidateIsSymmetric使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Matrix
的用法示例。
在下文中一共展示了Matrix.ValidateIsSymmetric方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Decompose
/// <summary>
/// Given a positive-definite symmetric matrix <c>A[0..n][0..n]</c>,
/// this routine constructs its Cholesky decomposition, <c> A = L*(L^T) </c>.
/// </summary>
/// <remarks>
/// The operations count is <c>(N^3)/6</c> executions of the inner loop (consisting of
/// one multiply and one subtract), with also N square roots.
/// This is about a factor 2 better than LU decomposition of <c>A</c>
/// (where its symmetry would be ignored).
/// </remarks>
/// <param name="matrix">Square Symmetric Definite-defined matrix A.
/// </param>
/// <exception cref="ArgumentNullException"><paramref name="matrix"/> is a null reference.</exception>
/// <exception cref="ArgumentException"><paramref name="matrix"/> is a not Symmetric.</exception>
/// <exception cref="ArgumentException"><paramref name="matrix"/> is a null Square.</exception>
/// <returns> The Cholesky factor L is returned</returns>
public void Decompose(Matrix matrix)
{
Guard.ArgumentNotNull(matrix, "a");
matrix.ValidateIsSymmetric();
var aRows = matrix.Rows;
var res = new Matrix(aRows, aRows);
for (var i = 0; i < aRows; i++)
{
int j;
for (j = i; j < aRows; j++)
{
int k;
double sum;
for (sum = matrix[i, j], k = i - 1; k >= 0; k--)
{
sum -= res[i, k] * res[j, k];
}
if (i == j)
{
if (sum <= 0)
{
throw new ArgumentException(isNotPositiveDefinite);
}
res[i, i] = Math.Sqrt(sum);
}
else
{
res[j, i] = sum / res[i, i];
}
}
}
LeftFactorMatrix = res;
}
示例2: QuickSolveLinearEquation
public static double[] QuickSolveLinearEquation(Matrix a, double[] b)
{
#region Validation
Guard.ArgumentNotNull(a, "a");
Guard.ArgumentNotNull(b, "b");
#endregion
a.ValidateIsSymmetric();
var aRowCount = a.Rows;
if (b.Length != aRowCount)
{
throw new ArgumentException(haveNonMatchingDimensions);
}
//L is a Cholesky Decomposition
var decomposeMatrix = QuickDecompose(a);
var x = new double[aRowCount];
int k;
double sum;
for (var i = 0; i < aRowCount; i++)
{
// Solve <c>L * y = b</c>, storing y in x.
for (sum = b[i], k = i - 1; k >= 0; k--)
{
sum -= decomposeMatrix[i, k] * x[k];
}
x[i] = sum / decomposeMatrix[i, i];
}
for (var i = aRowCount - 1; i >= 0; i--)
{
// Solve L^T * x = y.
for (sum = x[i], k = i + 1; k < aRowCount; k++)
{
sum -= decomposeMatrix[k, i] * x[k];
}
x[i] = sum / decomposeMatrix[i, i];
}
return x;
}
示例3: QuickDecompose
public static Matrix QuickDecompose(Matrix a)
{
Guard.ArgumentNotNull(a, "a");
a.ValidateIsSymmetric();
var aRowCount = a.Rows;
var res = new Matrix(aRowCount, aRowCount);
for (var i = 0; i < aRowCount; i++)
{
int j;
for (j = i; j < aRowCount; j++)
{
int k;
double sum;
for (sum = a[i, j], k = i - 1; k >= 0; k--)
{
sum -= res[i, k] * res[j, k];
}
if (i == j)
{
if (sum <= 0)
{
throw new ArgumentException(isNotPositiveDefinite);
}
res[i, i] = Math.Sqrt(sum);
}
else
{
res[j, i] = sum / res[i, i];
}
}
}
return res;
}