Esempio n. 1
0
        //Transpose matrix
        public MatrixDouble transpose()
        {
            MatrixDouble res = new MatrixDouble(this._m, this._n);

            for (int i = 0; i < this._m; i++)
            {
                for (int j = 0; j < this._n; j++)
                {
                    res._data[i][j] = this._data[j][i];
                }
            }
            return(res);
        }
Esempio n. 2
0
        //Identity matrix
        public MatrixDouble identity(int n)
        {
            MatrixDouble res = new MatrixDouble(n, n);

            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    res._data[i][j] = 1;
                }
            }
            return(res);
        }
Esempio n. 3
0
        //Addition
        public MatrixDouble addition(MatrixDouble mat)
        {
            if (this._m != mat._m || this._n != mat._n)
            {
                throw new Exception("Illegal matrix dimensions");
            }
            MatrixDouble res = new MatrixDouble(this._m, this._n);

            for (int i = 0; i < this._m; i++)
            {
                for (int j = 0; j < this._n; j++)
                {
                    res._data[i][j] = this._data[i][j] + mat._data[i][j];
                }
            }
            return(res);
        }
Esempio n. 4
0
        //To create a random matrix
        public MatrixDouble randomMatrix(int m, int n, int min, int max)
        {
            if (min >= max)
            {
                throw new Exception("Incompatible values");
            }
            Random       rnd = new Random();
            MatrixDouble res = new MatrixDouble(m, n);

            for (int i = 0; i < m; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    res._data[i][j] = min + (max - min) * rnd.NextDouble();
                }
            }
            return(res);
        }
Esempio n. 5
0
        //Multiplication
        public MatrixDouble multiplication(MatrixDouble mat)
        {
            if (this._n != mat._m)
            {
                throw new Exception("Invalide matrix dimensions");
            }
            MatrixDouble res = new MatrixDouble(this._m, mat._n);

            for (int i = 0; i < this._m; i++)
            {
                for (int j = 0; j < mat._n; j++)
                {
                    res._data[i][j] = 0;
                    for (int k = 0; k < this._n; k++)
                    {
                        res._data[i][j] += this._data[i][k] * mat._data[k][j];
                    }
                }
            }
            return(res);
        }
Esempio n. 6
0
        static void Main(string[] args)
        {
            //Crible d'Eratosthène

            /*Console.WriteLine("Veuillez entre votre nombre n.");
             * String inputString = Console.ReadLine();
             * int inputInteger;
             * bool success = int.TryParse(inputString, out inputInteger);
             * if (success)
             * {
             *  Console.WriteLine("Les nombres premiers compris entre 0 et n = " + inputInteger + " sont : ");
             *  CribleEratosthene.Program.display(CribleEratosthene.Program.cribleEratosthene(inputInteger));
             * }
             * else
             * {
             *  Console.WriteLine("Un problème est survenue, vous devez entre Veuillez entre votre nombre n.");
             *
             * }
             * Console.ReadLine();*/

            //Matrix
            double[] d1 = { 1, 2 };
            double[] d2 = { 4, 5 };
            double[] d3 = { 3, 9 };

            double[][] data =
            {
                d1,
                d2
            };

            MatrixDouble A = new MatrixDouble(data);

            A.displayMatrix();
            Console.ReadLine();
        }
Esempio n. 7
0
 //Constructor by copy
 public MatrixDouble(MatrixDouble mat)
 {
     this._m    = mat._m;
     this._n    = mat._n;
     this._data = mat._data;
 }