Click here to Skip to main content
15,884,388 members
Articles / Programming Languages / C#

MaNet: A matrix library for .NET (Rational Computing 2)

Rate me:
Please Sign up or sign in to vote.
4.90/5 (32 votes)
8 Jul 2010CPOL7 min read 56K   3.2K   74  
A translation of the Java matrix library JAMA with LU, QR, Eigenvalue, and Cholesky decompositions.
using System;
using MaNet;

namespace MaNet_NUnit
{
  public static  class StandardMatrixTests
    {
        public static bool IsUpperTriangular(Matrix m)
        {
            for (int iRow = 0; iRow < m.RowDimension; iRow++)
            {
                for (int iCol = 0; iCol < m.ColumnDimension; iCol++)
                {
                    if (iRow > iCol && m.Get(iRow, iCol) != 0) return false;
                }
            }
            return true;
        }


        public static bool IsLowerTriangular(Matrix m)
        {
            for (int iRow = 0; iRow < m.RowDimension; iRow++)
            {
                for (int iCol = 0; iCol < m.ColumnDimension; iCol++)
                {
                    if (iRow < iCol && m.Get(iRow, iCol) != 0) return false;
                }
            }
            return true;
        }

        public static bool IsDiagonal(Matrix m)
        {
            for (int iRow = 0; iRow < m.RowDimension; iRow++)
            {
                for (int iCol = 0; iCol < m.ColumnDimension; iCol++)
                {
                    if (iRow != iCol && m.Get(iRow, iCol) != 0) return false;
                }
            }
            return true;
        }


        public static bool IsSymetric(Matrix m)
        {
            if (m.RowDimension != m.ColumnDimension) return false;
            int n = m.ColumnDimension;
          bool  issymmetric = true;
            for (int j = 0; (j < n) & issymmetric; j++)
            {
                for (int i = 0; (i < n) & issymmetric; i++)
                {
                    issymmetric = (m.Get(i, j) == m.Get(j, i));
                }
            }
            return issymmetric;
        }


        public static  bool IsNonnegativeDiagonal(Matrix mat)
        {
            for (int i = 0; i < mat.RowDimension; i++)
            {
                for (int j = 0; j < mat.ColumnDimension; j++)
                {
                    if (i == j)
                    {
                        if (mat.Get(i, j) < 0) return false;
                    }
                    else
                    {
                       
                        if (mat.Get(i, j) != 0) return false;

                    }

                }
            }
            return true;

        }


        public static bool IsIntegerValued(Matrix mat)
        {
            for (int i = 0; i < mat.RowDimension; i++)
            {
                for (int j = 0; j < mat.ColumnDimension; j++)
                {
                    if (Math.Truncate(mat.Get(i, j)) != mat.Get(i, j)) return false;
                }
            }
            return true;

        }

    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
United States United States
Written software for what seems like forever. I'm currenly infatuated with WPF. Hopefully my affections are returned.

Comments and Discussions