/// <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); }
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)"); } }