Beispiel #1
0
        private _nVector HHStep1_2R(_mnMatrix matrix)
        {
            var resultAfterStep1 = HHStep1_1R(matrix);

            var scalar = (1 / resultAfterStep1.Norm(resultAfterStep1));
            var result = resultAfterStep1.MultiplyByScalar((1 / resultAfterStep1.Norm(resultAfterStep1)));

            return(result);
        }
Beispiel #2
0
        private _nVector HHStep1_1R(_mnMatrix matrix)
        {
            var m           = matrix.m;
            var firstRow    = matrix.GetRow(0);
            var coefficient = Sign(firstRow.V(1)) * firstRow.Norm(firstRow);
            var coefficientTimesUnitVector = iComponentVector(m).MultiplyByScalar(coefficient);
            var resultAfterAdd             = coefficientTimesUnitVector.Add(firstRow);

            return(resultAfterAdd);
        }
Beispiel #3
0
        public void InsertSubMatrix(_mnMatrix matrix, int mm, int k)
        {
            int skipRows = m - mm, skipCols = m - k;

            for (int i = skipRows; i < m; i++)
            {
                var nVector = new List <double>();
                for (int j = skipCols; j < m; j++)
                {
                    rows[i].vector[j] = matrix.rows[i - skipRows].vector[j - skipCols];
                }
            }
        }
Beispiel #4
0
        public _mnMatrix HouseholderRightSideResult(_mnMatrix mnMatrix, int i, int dim)
        {
            var U      = HHStep1_2R(mnMatrix);
            var result = mnMatrix.MultiplyByVector(U);
            var multiplicationResult = result.mnMatrixTypeMultiplyWithAnotherVector(U);
            var resultTimes2         = multiplicationResult.MultiplyByScalar(2);
            var subtractionResult    = mnMatrix.SubtractAnotherMatrix(resultTimes2);

            if (i > 1)
            {
                AddToVHouseholder(U, subtractionResult, i, dim);
            }
            return(subtractionResult);
        }
Beispiel #5
0
        public void AddToVHouseholder(_nVector V, _mnMatrix mnMatrix, int i, int dim)
        {
            var vMatrix = V.MatrixTypeMultiplyWithMe();
            var resultafterUMatrixTimes2 = vMatrix.MultiplyByScalar(2);
            var identity = new nIdentityMatrix();
            var finvlHouseholderMatrix = identity.ReturnNIdentityMatrix(i - 1)
                                         .SubtractAnotherMatrix(resultafterUMatrixTimes2);
            var matrixToAdd = identity.ReturnNIdentityMatrix(dim - 1);

            matrixToAdd.InsertSubMatrix(finvlHouseholderMatrix, i - 1);
            VHouseholderMatrices.Add(matrixToAdd);
            //var maybe = matrixToAdd.MultiplyByAnotherMatrix(matrixToAdd.ReturnTranspose(matrixToAdd));
            //var result = mnMatrix.MultiplyMeByNMatrix(matrixToAdd);
        }
Beispiel #6
0
        public _mnMatrix ReturnTranspose(_mnMatrix matrix)
        {
            var nn          = matrix.n; //rows
            var mm          = matrix.m; //columns
            var tempVectors = new List <_nVector>();

            for (int i = 0; i < mm; i++)
            {
                var tempVectorList = new List <double>();
                for (int j = 0; j < nn; j++)
                {
                    tempVectorList.Add(matrix.GetValueAt(j + 1, i + 1));
                }
                tempVectors.Add(new _nVector(tempVectorList));
            }
            return(new _mnMatrix(tempVectors, mm, nn));
        }
Beispiel #7
0
        public _mnMatrix SubtractAnotherMatrix(_mnMatrix 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 _mnMatrix(MatrixComponents, i, j));
        }