Exemplo n.º 1
0
        /// <summary>
        /// Generate column from initial matrix to work array
        /// </summary>
        /// <param name="a">Initial matrix</param>
        /// <param name="row">The first row</param>
        /// <param name="column">Column index</param>
        /// <returns>Generated vector</returns>
        private static Complex[] GenerateColumn(Matrix<Complex> a, int row, int column)
        {
            var ru = a.RowCount - row;
            var u = new Complex[ru];

            for (var i = row; i < a.RowCount; i++)
            {
                u[i - row] = a.At(i, column);
                a.At(i, column, 0.0);
            }

            var norm = u.Aggregate(Complex.Zero, (current, t) => current + (t.Magnitude * t.Magnitude));
            norm = norm.SquareRoot();

            if (row == a.RowCount - 1 || norm.Magnitude == 0)
            {
                a.At(row, column, -u[0]);
                u[0] = Math.Sqrt(2.0);
                return u;
            }

            if (u[0].Magnitude != 0.0)
            {
                norm = norm.Magnitude * (u[0] / u[0].Magnitude);
            }

            a.At(row, column, -norm);

            for (var i = 0; i < ru; i++)
            {
                u[i] /= norm;
            }

            u[0] += 1.0;

            var s = (1.0 / u[0]).SquareRoot();
            for (var i = 0; i < ru; i++)
            {
                u[i] = u[i].Conjugate() * s;
            }

            return u;
        }