public void NullParameterTestforSolveMatrix()
		{
			ComplexDoubleSymmetricLevinson cdsl = new ComplexDoubleSymmetricLevinson(T5);
			ComplexDoubleMatrix X = cdsl.Solve(null as ComplexDoubleMatrix);
		}
		public void MismatchRowsTestforSolveMatrix()
		{
			ComplexDoubleSymmetricLevinson cdsl = new ComplexDoubleSymmetricLevinson(T4);
			ComplexDoubleMatrix X = cdsl.Solve(I5);
		}
		public void MismatchRowsTestforSolveVector()
		{
			ComplexDoubleSymmetricLevinson cdsl = new ComplexDoubleSymmetricLevinson(T4);
			ComplexDoubleVector X = cdsl.Solve(X5);
		}
		public void SolveVector5()
		{
			int i;
			double e, me;
			ComplexDoubleSymmetricLevinson cdsl = new ComplexDoubleSymmetricLevinson(T5);
			ComplexDoubleVector X = cdsl.Solve(Y5);

			// determine the maximum error
			me = 0.0;
			for (i = 0; i < cdsl.Order; i++)
			{
				e = ComplexMath.Absolute((X5[i] - X[i]) / X5[i]);
				if (e > me)
				{
					me = e;
				}
			}
			Assert.IsTrue(me < Tolerance5, "Maximum Error = " + me.ToString());
		}
		public void GetDeterminantMethodTest5()
		{
			// calculate determinant from diagonal
			ComplexDoubleSymmetricLevinson cdsl = new ComplexDoubleSymmetricLevinson(T5);

			// check results match
			double e = ComplexMath.Absolute((cdsl.GetDeterminant() - Det5) / Det5);
			Assert.IsTrue(e < Tolerance5);
		}
		public void NullParameterTestforSolveVector()
		{
			ComplexDoubleSymmetricLevinson cdsl = new ComplexDoubleSymmetricLevinson(T5);
			ComplexDoubleVector X = cdsl.Solve(null as ComplexDoubleVector);
		}
		public void SingularityPropertyTest5()
		{
			ComplexDoubleSymmetricLevinson cdsl = new ComplexDoubleSymmetricLevinson(T5);
			Assert.IsFalse(cdsl.IsSingular);
		}
		public void NullParameterTestforConstructor()
		{
			ComplexDoubleSymmetricLevinson cdsl = new ComplexDoubleSymmetricLevinson(null as ComplexDoubleVector);
		}
		public void OrderPropertyTest()
		{
			ComplexDoubleSymmetricLevinson cdsl = new ComplexDoubleSymmetricLevinson(T5);
			Assert.IsTrue(cdsl.Order == 5);
		}
		public void DecompositionTest5()
		{
			int i, j;
			double e, me;
			ComplexDoubleSymmetricLevinson cdsl = new ComplexDoubleSymmetricLevinson(T5);
			ComplexDoubleMatrix U = cdsl.U;
			ComplexDoubleMatrix D = cdsl.D;
			ComplexDoubleMatrix L = cdsl.L;

			// check U is the transpose of L
			Assert.IsTrue(U.Equals(L.GetTranspose()));

			// check the lower triangle
			me = 0.0;
			for (i = 0; i < cdsl.Order; i++)
			{
				for (j = 0; j <= i; j++)
				{
					e = ComplexMath.Absolute((L5[i, j] - L[i, j]) / L5[i, j]);
					if (e > me)
					{
						me = e;
					}
				}
			}
			Assert.IsTrue(me < Tolerance5, "Maximum Error = " + me.ToString());

			// check the diagonal
			me = 0.0;
			for (i = 0; i < cdsl.Order; i++)
			{
				e = ComplexMath.Absolute((D5[i] - D[i, i]) / D5[i]);
				if (e > me)
				{
					me = e;
				}
			}

			Assert.IsTrue(me < Tolerance5, "Maximum Error = " + me.ToString());
		}
		public void GetMatrixMemberTest()
		{
			ComplexDoubleSymmetricLevinson cdsl = new ComplexDoubleSymmetricLevinson(T5);
			ComplexDoubleMatrix cdsldm = cdsl.GetMatrix();
			for (int row = 0; row < T5.Length; row++)
			{
				for (int column = 0; column < T5.Length; column++)
				{
					if (column < row)
					{
						Assert.IsTrue(cdsldm[row, column] == T5[row - column]);
					}
					else
					{
						Assert.IsTrue(cdsldm[row, column] == T5[column - row]);
					}
				}
			}
		}
		public void GetVectorMemberTest()
		{
			ComplexDoubleSymmetricLevinson cdsl = new ComplexDoubleSymmetricLevinson(T5);
			ComplexDoubleVector TT = cdsl.GetVector();
			Assert.IsTrue(T5.Equals(TT));
		}
		public void ZeroLengthVectorTestsforConstructor1()
		{
			ComplexDoubleVector cdv = new ComplexDoubleVector(1, 0.0);
			cdv.RemoveAt(0);
			ComplexDoubleSymmetricLevinson cdsl = new ComplexDoubleSymmetricLevinson(cdv);
		}
		public void SolveMatrix1()
		{
			int i, j;
			double e, me;
			ComplexDoubleSymmetricLevinson cdsl = new ComplexDoubleSymmetricLevinson(T1);

			// check inverse
			ComplexDoubleMatrix I = cdsl.Solve(ComplexDoubleMatrix.CreateIdentity(1));
			me = 0.0;
			for (i = 0; i < cdsl.Order; i++)
			{
				for (j = 0; j < cdsl.Order; j++)
				{
					e = ComplexMath.Absolute((I1[i, j] - I[i, j]) / I1[i, j]);
					if (e > me)
					{
						me = e;
					}
				}
			}
			Assert.IsTrue(me < Tolerance1, "Maximum Error = " + me.ToString());
		}
		public void SingularityPropertyTest()
		{
			ComplexDoubleVector T = new ComplexDoubleVector(10);
			for (int i = 1; i < 10; i++)
			{
				T[i] = new Complex((double)(i + 1), (double)(i + 1));
			}
			T[0] = new Complex(2.0, 2.0);

			ComplexDoubleSymmetricLevinson cdsl = new ComplexDoubleSymmetricLevinson(T);
			Assert.IsTrue(cdsl.IsSingular);
		}
Esempio n. 16
0
        /// <summary>
        /// Invert a symmetric square Toeplitz matrix.
        /// </summary>
        /// <param name="T">The left-most column of the symmetric Toeplitz matrix.</param>
        /// <returns>The inverse matrix.</returns>
        /// <exception cref="ArgumentNullException">
        /// <B>T</B> is a null reference.
        /// </exception>
        /// <exception cref="RankException">
        /// The length of <B>T</B> must be greater than zero.
        /// </exception>
        /// <exception cref="SingularMatrixException">
        /// The Toeplitz matrix or one of the the leading sub-matrices is singular.
        /// </exception>
        /// <remarks>
        /// This static member combines the <b>UDL</b> decomposition and Trench's algorithm into a
        /// single algorithm. When compared to the non-static member it requires minimal data storage
        /// and suffers from no speed penalty.
        /// <para>
        /// Trench's algorithm requires <b>N</b> squared FLOPS, compared to <b>N</b> cubed FLOPS
        /// if we simply solved a linear Toeplitz system with a right-side identity matrix (<b>N</b> is the matrix order).
        /// </para>
        /// </remarks>
        public static ComplexDoubleMatrix Inverse(IROComplexDoubleVector T)
        {
            ComplexDoubleMatrix X;

            // check parameters
            if (T == null)
            {
                throw new System.ArgumentNullException("T");
            }
            else if (T.Length < 1)
            {
                throw new System.RankException("The length of T must be greater than zero.");
            }
            else if (T.Length == 1)
            {
                X       = new ComplexDoubleMatrix(1);
                X[0, 0] = Complex.One / T[0];
            }
            else
            {
                int     N = T.Length;
                Complex f, g;
                int     i, j, l, k, m, n;
                X = new ComplexDoubleMatrix(N);

                // calculate the predictor coefficients
                ComplexDoubleVector Y = ComplexDoubleSymmetricLevinson.YuleWalker(T);

                // calculate gamma
                f = T[0];
                for (i = 1, j = 0; i < N; i++, j++)
                {
                    f += T[i] * Y[j];
                }
                g = Complex.One / f;

                // calculate first row of inverse
                X[0, 0] = g;
                for (i = 1, j = 0; i < N; i++, j++)
                {
                    X[0, i] = g * Y[j];
                }

                // calculate successive rows of upper wedge
                for (i = 0, j = 1, k = N - 2; i < N / 2; i++, j++, k--)
                {
                    for (l = j, m = i, n = N - 1 - j; l < N - j; l++, m++, n--)
                    {
                        X[j, l] = X[i, m] + g * (Y[i] * Y[m] - Y[k] * Y[n]);
                    }
                }

                // this is symmetric matrix ...
                for (i = 0; i <= N / 2; i++)
                {
                    for (j = i + 1; j < N - i; j++)
                    {
                        X[j, i] = X[i, j];
                    }
                }

                // and a persymmetric matrix.
                for (i = 0, j = N - 1; i < N; i++, j--)
                {
                    for (k = 0, l = N - 1; k < j; k++, l--)
                    {
                        X[l, j] = X[i, k];
                    }
                }
            }

            return(X);
        }
		public void GetInverse5()
		{
			int i, j;
			double e, me;
			ComplexDoubleSymmetricLevinson cdsl = new ComplexDoubleSymmetricLevinson(T5);

			// check inverse
			ComplexDoubleMatrix I = cdsl.GetInverse();
			me = 0.0;
			for (i = 0; i < cdsl.Order; i++)
			{
				for (j = 0; j < cdsl.Order; j++)
				{
					e = ComplexMath.Absolute((I5[i, j] - I[i, j]) / I5[i, j]);
					if (e > me)
					{
						me = e;
					}
				}
			}
			Assert.IsTrue(me < Tolerance5, "Maximum Error = " + me.ToString());
		}