Exemple #1
0
        public _nVector MultiplyByVector(_nVector vector)
        {
            double[,] a = new double[n, n];
            for (int j = 1; j <= n; j++)
            {
                for (int i = 1; i <= n; i++)
                {
                    a[i - 1, j - 1] = GetValueAt(j, i) * vector.V(i);
                }
            }

            var vec = new List <double>();

            for (int i = 0; i < n; i++)
            {
                double temp = 0;
                for (int j = 0; j < n; j++)
                {
                    temp += a[i, j];
                }
                vec.Add(temp);
            }

            return(new _nVector(vec));
        }
Exemple #2
0
        public double Norm(_nVector vec)
        {
            double sum = 0;

            foreach (var component in vec.vector)
            {
                sum += Math.Pow(component, 2);
            }
            return(Math.Sqrt(sum));
        }
Exemple #3
0
        public double DotProductWithAnotherVectorTranspose(_nVector vec)
        {
            double magnitude = 0;
            int    ctr       = 0;

            foreach (var component in vector)
            {
                magnitude += component * vec.vector[ctr];
                ctr++;
            }
            return(magnitude);
        }
Exemple #4
0
        public _nVector Subtract(_nVector nVector)
        {
            var vec  = new List <double>();
            int cntr = 0;

            foreach (var value in vector)
            {
                vec.Add(value - nVector.vector[cntr]);
                cntr++;
            }
            return(new _nVector(vec));
        }
Exemple #5
0
        public _nVector GetSubRow(int m, int k)
        {
            var mRows = new List <_nVector>();
            int skipRows = n - m, skipCols = n - k;
            var nVector = new List <double>();

            for (int j = skipCols; j < n; j++)
            {
                nVector.Add(rows[skipRows].vector[j]);
            }
            var tempNVector = new _nVector(nVector);


            return(tempNVector);
        }
Exemple #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="m"> Row </param>
        /// <param name="k"> Column </param>
        /// <returns></returns>
        public _mnMatrix GetSubMatrix(int m, int k)
        {
            var mRows = new List <_nVector>();
            int skipRows = m, skipCols = k;

            for (int i = skipRows; i < n; i++)
            {
                var nVector = new List <double>();
                for (int j = skipCols; j < n; j++)
                {
                    nVector.Add(rows[i].vector[j]);
                }
                var tempNVector = new _nVector(nVector);
                mRows.Add(tempNVector);
            }
            return(new _mnMatrix(mRows, n - k, n - m));
        }
Exemple #7
0
        public _mnMatrix mnMatrixTypeMultiplyWithAnotherVector(_nVector vec)
        {
            var componentList = new List <double>();
            var dictionary = new List <_nVector>();
            int i = 0, j = 0;

            foreach (var component in vector)
            {
                var vctor = new List <double>();
                foreach (var component2 in vec.vector)
                {
                    vctor.Add(component * component2);
                }
                dictionary.Add(new _nVector(vctor));
                i++;
            }
            return(new _mnMatrix(dictionary, i, j));
        }
Exemple #8
0
        public _nMatrix MultiplyByAnotherMatrix(_nMatrix matrix)
        {
            _nVector[] _row = new _nVector[n];
            double[]   a    = new double[n];
            for (int k = 1; k <= n; k++)
            {
                for (int j = 1; j <= n; j++)
                {
                    for (int i = 1; i <= n; i++)
                    {
                        var tmp1 = GetValueAt(k, i); var tmp2 = matrix.GetValueAt(i, j);
                        a[j - 1] += GetValueAt(k, i) * matrix.GetValueAt(i, j);
                    }
                    var tmp3 = a[j - 1];
                }

                _row[k - 1] = new _nVector(a.ToList());
                a           = new double[n];
            }
            return(new _nMatrix(_row.ToList(), n));
        }
Exemple #9
0
        public _nMatrix MatrixTypeMultiplyWithAnotherVector(_nVector vec)
        {
            var componentList = new List <double>();
            int n             = this.vector.Count();

            double[,] matrixComponents = new double[n, n];
            var dictionary = new List <_nVector>();
            int i          = 0;

            foreach (var component in vector)
            {
                var vctor = new List <double>();
                foreach (var component2 in vec.vector)
                {
                    vctor.Add(component * component2);
                }
                dictionary.Add(new _nVector(vctor));
                i++;
            }
            return(new _nMatrix(dictionary, n));
        }
Exemple #10
0
        public _nMatrix ReturnNIdentityMatrix(int n)
        {
            var matrixRows = new List <_nVector>();

            for (int i = 0; i < n; i++)
            {
                var row = new List <double>();
                for (int j = 0; j < n; j++)
                {
                    if (j == i)
                    {
                        row.Add(1);
                    }
                    else
                    {
                        row.Add(0);
                    }
                }
                var vectorRow = new _nVector(row);
                matrixRows.Add(vectorRow);
            }
            return(new _nMatrix(matrixRows, n));
        }
Exemple #11
0
        public _mnMatrix MultiplyMeByNMatrix(_nMatrix matrix)
        {
            _nVector[] _row = new _nVector[n];
            var        mm   = matrix.rows.Count();

            double[] a = new double[n];
            for (int k = 1; k <= n; k++)
            {
                for (int j = 1; j <= mm; j++)
                {
                    for (int i = 1; i <= mm; i++)
                    {
                        //var tmp1 = GetValueAt(k, i); var tmp2 = matrix.GetValueAt(i, j);
                        a[j - 1] += GetValueAt(k, i) * matrix.GetValueAt(i, j);
                    }
                    // var tmp3 = a[j - 1];
                }

                _row[k - 1] = new _nVector(a.ToList());
                a           = new double[n];
            }
            return(new _mnMatrix(_row.ToList(), n, mm));
        }