예제 #1
0
        // storage is in lower triangular form, i.e. values[r][c] with c <= r

        /// <summary>
        /// Initializes a new symmetric matrix.
        /// </summary>
        /// <param name="dimension">The dimension of the matrix, which must be positive.</param>
        public SymmetricMatrix(int dimension)
        {
            if (dimension < 1)
            {
                throw new ArgumentOutOfRangeException("dimension");
            }
            this.dimension = dimension;
            values         = SymmetricMatrixAlgorithms.InitializeStorage(dimension);
        }
예제 #2
0
 /// <summary>
 /// Copies the matrix.
 /// </summary>
 /// <returns>An independent copy of the matrix.</returns>
 public SymmetricMatrix Copy()
 {
     double[][] copy = SymmetricMatrixAlgorithms.InitializeStorage(dimension);
     for (int r = 0; r < Dimension; r++)
     {
         for (int c = 0; c <= r; c++)
         {
             copy[r][c] = values[r][c];
         }
     }
     return(new SymmetricMatrix(copy, dimension));
 }
예제 #3
0
 /// <summary>
 /// Negates a symmetric matrix.
 /// </summary>
 /// <param name="A">The matrix.</param>
 /// <returns>The matrix -A.</returns>
 public static SymmetricMatrix operator -(SymmetricMatrix A)
 {
     if (A == null)
     {
         throw new ArgumentNullException("A");
     }
     double[][] resultStore = SymmetricMatrixAlgorithms.InitializeStorage(A.dimension);
     for (int r = 0; r < A.Dimension; r++)
     {
         for (int c = 0; c <= r; c++)
         {
             resultStore[r][c] = -A.values[r][c];
         }
     }
     return(new SymmetricMatrix(resultStore, A.dimension));
 }
예제 #4
0
 /// <summary>
 /// Multiplies a symmetric matrix by a real factor.
 /// </summary>
 /// <param name="alpha">The factor.</param>
 /// <param name="A">The matrix.</param>
 /// <returns>The product of the matrix and the factor.</returns>
 public static SymmetricMatrix operator *(double alpha, SymmetricMatrix A)
 {
     if (A == null)
     {
         throw new ArgumentNullException(nameof(A));
     }
     double[][] productStore = SymmetricMatrixAlgorithms.InitializeStorage(A.dimension);
     for (int r = 0; r < A.Dimension; r++)
     {
         for (int c = 0; c <= r; c++)
         {
             productStore[r][c] = alpha * A.values[r][c];
         }
     }
     return(new SymmetricMatrix(productStore, A.dimension));
 }
예제 #5
0
 /// <summary>
 /// Subtracts two symmetric matrices.
 /// </summary>
 /// <param name="A">The first matrix.</param>
 /// <param name="B">The second matrix.</param>
 /// <returns>The difference <paramref name="A"/> - <paramref name="B"/>.</returns>
 public static SymmetricMatrix operator -(SymmetricMatrix A, SymmetricMatrix B)
 {
     if (A == null)
     {
         throw new ArgumentNullException("A");
     }
     if (B == null)
     {
         throw new ArgumentNullException("B");
     }
     if (A.dimension != B.dimension)
     {
         throw new DimensionMismatchException();
     }
     double[][] differenceStore = SymmetricMatrixAlgorithms.InitializeStorage(A.dimension);
     for (int r = 0; r < A.dimension; r++)
     {
         for (int c = 0; c <= r; c++)
         {
             differenceStore[r][c] = A.values[r][c] - B.values[r][c];
         }
     }
     return(new SymmetricMatrix(differenceStore, A.dimension));
 }