Esempio n. 1
0
 /// <returns>true when exact 'value' is anywhere on the diagonal.</returns>
 public static bool HasValueOnDiagonal(DotNetMatrix.GeneralMatrix m, double value)
 {
     for (int i = 0; i < Math.Min(m.RowDimension, m.ColumnDimension); i++)
     {
         if (m.GetElement(i, i) == value)
         {
             return(true);
         }
     }
     return(false);
 }
Esempio n. 2
0
        public static String ToString(DotNetMatrix.GeneralMatrix m)
        {
            System.Text.StringBuilder result = new System.Text.StringBuilder();

            for (int i = 0; i < m.RowDimension; i++)
            {
                for (int j = 0; j < m.ColumnDimension; j++)
                {
                    result.Append(m.GetElement(i, j));
                    result.Append(" ");
                }
                result.Append("\n");
            }
            return(result.ToString());
        }
Esempio n. 3
0
        public static bool IsDiagonal(DotNetMatrix.GeneralMatrix m)
        {
            const double EPS = 1e-6;

            for (int i = 0; i < m.RowDimension; i++)
            {
                for (int j = 0; j < m.ColumnDimension; j++)
                {
                    if ((i != j) && (Math.Abs(m.GetElement(i, j)) > EPS))
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
Esempio n. 4
0
 /// <summary>
 /// Returns true when the matrix is diagonal and has only exact 0, +1 and/or -1 entries on the diagonal.
 /// </summary>
 /// <param name="m">the (square) matrix</param>
 /// <returns></returns>
 public static bool IsSimpleDiagonal(DotNetMatrix.GeneralMatrix m)
 {
     for (int i = 0; i < m.RowDimension; i++)
     {
         for (int j = 0; j < m.ColumnDimension; j++)
         {
             double v = m.GetElement(i, j);
             if ((i != j) && (v != 0.0))
             {
                 return(false);
             }
             else if (i == j)
             {
                 if (!((v == 0.0) || (v == 1.0) || (v == -1.0)))
                 {
                     return(false);
                 }
             }
         }
     }
     return(true);
 }