Exemplo n.º 1
0
        public void ZeroOutRight(_nMatrix matrix)
        {
            int cntr = 0;

            foreach (var vctor in matrix.rows)
            {
                for (int i = 0; i < n; i++)
                {
                    if (i >= cntr + 1)
                    {
                        vctor.Value.vector[i] = 0;
                    }
                }
                cntr++;
            }
        }
Exemplo n.º 2
0
        public _nVector MultiplyByMatrix(_nMatrix matrix)
        {
            var n             = matrix.n;
            var componentList = new List <double>();

            for (int i = 0; i < n; i++)
            {
                double sum = 0;
                for (int j = 0; j < n; j++)
                {
                    sum += vector[j] * matrix.GetValueAt(j + 1, i + 1);
                }
                componentList.Add(sum);
            }
            return(new _nVector(componentList));
        }
Exemplo n.º 3
0
        public static void ZeroOutRightUptoI(_nMatrix matrix, int I)
        {
            int cntr = 0;
            var n    = matrix.n;

            foreach (var vctor in matrix.rows)
            {
                for (int i = 0; i < n; i++)
                {
                    if (i >= cntr + 1 && i < cntr + I && cntr + I < n)
                    {
                        vctor.Value.vector[i] = 0;
                    }
                }
                cntr++;
            }
        }
Exemplo n.º 4
0
        private static void AddNextPowerTermToMatrixSeries(_nMatrix copy, ref _nMatrix temp, int i)
        {
            int remainder = 0;

            Math.DivRem(i, 2, out remainder);
            if (remainder == 0)
            {
                var tmp = MatrixToThePowerN(i, copy);
                //ZeroOutRightUptoI(tmp, i);
                temp = temp.AddAnotherMatrix(tmp);
            }
            else
            {
                var tmp = MatrixToThePowerN(i, copy);
                //ZeroOutRightUptoI(tmp, i);
                temp = temp.SubtractAnotherMatrix(tmp);
            }
        }
Exemplo n.º 5
0
        public void ZeroOutLeft(_nMatrix matrix)
        {
            int row  = 0;
            int cntr = 0;

            foreach (var vctor in matrix.rows)
            {
                if (row != 0)
                {
                    for (int i = 0; i <= cntr; i++)
                    {
                        vctor.Value.vector[i] = 0;
                    }
                    cntr++;
                }
                row++;
            }
        }
Exemplo n.º 6
0
        public _nMatrix CreateCopy(_nMatrix matrix)
        {
            var matrixRows = new List <_nVector>();
            int cntr       = 0;

            foreach (var vctor in matrix.rows)
            {
                var tempVecList = new List <double>();
                for (int i = 0; i < matrix.n; i++)
                {
                    tempVecList.Add(vctor.Value.vector[i]);
                }
                matrixRows.Add(new _nVector(tempVecList));
                cntr++;
            }

            return(new _nMatrix(matrixRows, matrix.n));
        }
Exemplo n.º 7
0
        public _nMatrix SubtractAnotherMatrix(_nMatrix matrix)
        {
            var MatrixComponents = new List <_nVector>();
            int i = 1, j = 1;

            foreach (var vctor in rows)
            {
                var tmpVctor = new List <double>();
                foreach (var component in vctor.Value.vector)
                {
                    tmpVctor.Add(component - matrix.GetValueAt(i, j));
                    j++;
                }
                MatrixComponents.Add(new _nVector(tmpVctor));
                j = 1;
                i++;
            }
            return(new _nMatrix(MatrixComponents, n));
        }
Exemplo n.º 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));
        }
Exemplo n.º 9
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));
        }