当前位置: 首页>>代码示例>>C#>>正文


C# Matrix.ValidateIsSymmetric方法代码示例

本文整理汇总了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;
      }
开发者ID:Ivan-Dimitrov-bg,项目名称:.Net-framework,代码行数:58,代码来源:CholeskyDecomposition.cs

示例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;
        }
开发者ID:GTuritto,项目名称:ngenerics,代码行数:45,代码来源:CholeskyDecomposition.cs

示例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;
        }
开发者ID:GTuritto,项目名称:ngenerics,代码行数:39,代码来源:CholeskyDecomposition.cs


注:本文中的System.Matrix.ValidateIsSymmetric方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。