public void TestMethod1()
        {
            Vector a = new Vector();
            Vector b = new Vector(2, 3, 4, 5);
            Vector c = new Vector();

            c.Add(2);
            c.Add(3);

            double result = c[0];

            Matrix m = new Matrix();
            Matrix n = new Matrix(new Vector(1, 2, 3, 4, 5),
                                  new Vector(6, 7, 8, 9, 10));

            Vector[] vectorColletion = new Vector[] { };

            Matrix ar = new double[3][]
            {
                new double[]{4},
                new double[]{5},
                new double[]{6}
            };

            double abc = ar[1][0];

            Matrix ab = new Matrix(4, 4);
        }
Esempio n. 2
0
        /// <summary>
        /// Contructor for defining the <paramref name="rows"/> and columns, <paramref name="colls"/>.
        /// </summary>
        /// <param name="rows">The numbers of rows.</param>
        /// <param name="colls">The number of columns.</param>
        public Matrix(int rows, int colls)
        {
            _matrixContent = new Vector[rows];

            for (var i = 0; i < rows; i++)
                _matrixContent[i] = new Vector {Length = colls};
        }
        public void VectorOperations()
        {
            var vecA = new Vector(1, 2, 3, 4, 5);
            var vecB = new Vector(3, 4, 5, 6, 7);
            var result = vecA + vecB;

            Assert.AreEqual(result, new Vector(4, 6, 8, 10, 12));
        }
        public void VectorComparison()
        {
            var vecA = new Vector(1, 2, 3, 4, 5);
            var vecB = new Vector(1, 2, 3, 4, 5);

            Assert.AreEqual(vecA, vecB);

            var vecC = new Vector(1, 2, 3, 4, 5, 6);

            Assert.AreNotEqual(vecA, vecC);
        }
        public void TestToString()
        {
            var matrix = new Matrix(2, 2);
            
            matrix[0] = new Vector(1, 2);
            matrix[1] = new Vector(3, 4);
            
            Assert.AreEqual("1 2\r\n3 4", matrix.ToString());

            var vector = new Vector(1, 2, 3, 4);

            Assert.AreEqual("1 2 3 4", vector.ToString());
        }
Esempio n. 6
0
        private static bool ComparsionOperation(Vector vec1, Vector vec2, Func<double, double, bool> comparsionOperation)
        {
            Vector maxLengthVector;
            Vector minLengthVector;

            if (vec1.Length <= vec2.Length)
            {
                minLengthVector = vec1;
                maxLengthVector = vec2;
            }
            else
            {
                minLengthVector = vec2;
                maxLengthVector = vec1;
            }

            if (comparsionOperation(maxLengthVector.Length, minLengthVector.Length))
            {
                for (var i = 0; i < maxLengthVector.Length; i++)
                {
                    if (i >= minLengthVector.Length)
                        continue;
                    if (!comparsionOperation(vec1[i], vec2[i]))
                        return false;
                }
            }
            else
                return false;

            return true;
        }
Esempio n. 7
0
        //other functions
        
        private static Vector Operation(Vector vec1, Vector vec2, Func<double,double,double> operation)
        {
            Vector maxLengthVector;
            Vector minLengthVector;
            
            if (vec1.Length <= vec2.Length)
            {
                minLengthVector = vec1;
                maxLengthVector = vec2;
            }
            else
            {
                minLengthVector = vec2;
                maxLengthVector = vec1;
            }

            var result = new Vector { Length = maxLengthVector.Length };
            
            for (var i = 0; i < maxLengthVector.Length; i++)
            {
                if (i < minLengthVector.Length)
                    result[i] = operation(vec1[i], vec2[i]);
                else
                    result[i] = maxLengthVector[i];
            }

            return result;
        }
Esempio n. 8
0
        /**********************************************
         * private constructor
         * provides input of a matrix x, and row index and colIndex
         * output is a matrix derived from x, which does not include 
         * elements from row and col provided
         * private becasue it is not for public consumption but only 
         * used by Determinant
        ***********************************************/
        private Matrix(Matrix x, int row, int coll)
        {
            int counteri = 0, counterj = 0;
            _matrixContent = new Vector[x._matrixContent.Length - 1];

            for (var i = 0; i < x._matrixContent.Length; i++)
            {
                if (i != row)
                    _matrixContent[counteri] = new Vector { Length = x._matrixContent[0].Length - 1 };
                
                var bIncrementcounter = false;
                
                for (var j = 0; j < x._matrixContent[0].Length; j++)
                {
                    if ((i == row) || (j == coll)) continue;
                    
                    _matrixContent[counteri][counterj++] = x._matrixContent[i][j];
                    bIncrementcounter = true;
                }

                if (!bIncrementcounter) continue;
                
                counteri++;
                counterj = 0;
            }
        }