/// <summary>
        /// Householder Reflection: Evaluate symmetric? unitary Q such that Q*v = -sigma*||v||*e1 
        /// </summary>
        public static ComplexMatrix Reflection(ComplexVector v)
        {
            Complex sigma = v[0].Sign;

            ComplexVector u = v.Clone();
            u[0] += sigma * v.Norm();

            ComplexMatrix m = ComplexMatrix.Identity(v.Length, v.Length);
            m.MultiplyAccumulateInplace(u.TensorMultiply(u), -2d / u.ScalarMultiply(u));

            return m;
        }
        /// <summary>
        /// Householder Reflection: Evaluate symmetric? unitary Q such that Q*v = -sigma*||v||*e1
        /// </summary>
        public static ComplexMatrix Reflection(ComplexVector v)
        {
            Complex sigma = v[0].Sign;

            ComplexVector u = v.Clone();

            u[0] += sigma * v.Norm();

            ComplexMatrix m = ComplexMatrix.Identity(v.Length, v.Length);

            m.MultiplyAccumulateInplace(u.TensorMultiply(u), -2d / u.ScalarMultiply(u));

            return(m);
        }
Esempio n. 3
0
        public void TestOrthogonalRotationComplex()
        {
            StandardDistribution gaussian = new StandardDistribution();

            for (int i = 0; i < 100; i++)
            {
                ComplexVector v        = new ComplexVector(new Complex[] { Complex.Random(gaussian), Complex.Random(gaussian) });
                ComplexMatrix rotation = Orthogonal.Rotation(v);
                ComplexVector res      = rotation * v;
                Assert.That(rotation.HermitianTranspose() * rotation, NumericIs.AlmostEqualTo(ComplexMatrix.Identity(2, 2)), "unitary rotation matrix");
                Assert.That(rotation[0, 0].IsReal, "c1 real");
                Assert.That(rotation[1, 1].IsReal, "c2 real");
                Assert.That(res[0].Modulus, NumericIs.AlmostEqualTo(v.Norm(), 1e-12), "res(1)");
                Assert.That(res[1], NumericIs.AlmostEqualTo((Complex)0, 1e-12), "res(2)");
            }
        }
 public void TestOrthogonalReflectionComplex()
 {
     StandardDistribution gaussian = new StandardDistribution();
     for(int i = 0; i < 100; i++)
     {
         ComplexVector v = new ComplexVector(new Complex[] { Complex.Random(gaussian), Complex.Random(gaussian), Complex.Random(gaussian), Complex.Random(gaussian) });
         ComplexMatrix reflection = Orthogonal.Reflection(v);
         ComplexVector res = reflection * v;
         Assert.That(reflection.HermitianTranspose() * reflection, NumericIs.AlmostEqualTo(ComplexMatrix.Identity(4, 4)), "orthogonal reflection matrix");
         Assert.That(reflection[0, 0].IsReal, "c1 real");
         Assert.That(reflection[1, 1].IsReal, "c2 real");
         Assert.That(reflection[2, 2].IsReal, "c3 real");
         Assert.That(reflection[3, 3].IsReal, "c4 real");
         Assert.That(res[0].Modulus, NumericIs.AlmostEqualTo(v.Norm(), 1e-12), "res(1)");
         Assert.That(res[1], NumericIs.AlmostEqualTo((Complex) 0, 1e-12), "res(2)");
         Assert.That(res[2], NumericIs.AlmostEqualTo((Complex) 0, 1e-12), "res(3)");
         Assert.That(res[3], NumericIs.AlmostEqualTo((Complex) 0, 1e-12), "res(4)");
     }
 }