示例#1
0
        public void Conjugate_a_purely_imaginary_number()
        {
            var sut      = new ComplexNumber(0, 5);
            var expected = new ComplexNumber(0, -5);

            Assert.Equal(expected.Real, sut.Conjugate().Real, precision: 7);
            Assert.Equal(expected.Imaginary, sut.Conjugate().Imaginary, precision: 7);
        }
示例#2
0
        public void Conjugate_a_number_with_real_and_imaginary_part()
        {
            var sut      = new ComplexNumber(1, 1);
            var expected = new ComplexNumber(1, -1);

            Assert.Equal(expected.Real, sut.Conjugate().Real, precision: 7);
            Assert.Equal(expected.Imaginary, sut.Conjugate().Imaginary, precision: 7);
        }
示例#3
0
    public void Conjugate_a_purely_real_number()
    {
        var sut      = new ComplexNumber(5, 0);
        var expected = new ComplexNumber(5, 0);

        Assert.Equal(expected.Real(), sut.Conjugate().Real(), precision: 7);
        Assert.Equal(expected.Imaginary(), sut.Conjugate().Imaginary(), precision: 7);
    }
示例#4
0
        public void MethodTests()
        {
            // Try and parse a b-positive and a b-negative complex numbers from two strings
            String bPositive = "1 + 5i";
            String bNegative = "1 - 3i";
            // Try and calculate a b-positive and a b-negative conjugate
            ComplexNumber bpComplex = new ComplexNumber(1, 3);
            ComplexNumber bnComplex = new ComplexNumber(-3, -2);

            // Parse the thingies
            ComplexNumber result1 = ComplexNumber.ParseFromString(bPositive);
            ComplexNumber result2 = ComplexNumber.ParseFromString(bNegative);
            // Calculate the conjugate
            ComplexNumber bpConjugate = bpComplex.Conjugate();
            ComplexNumber bnConjugate = bnComplex.Conjugate();

            // What do we expect?
            ComplexNumber expected1    = new ComplexNumber(1, 5);
            ComplexNumber expected2    = new ComplexNumber(1, -3);
            ComplexNumber ebpConjugate = new ComplexNumber(1, -3);
            ComplexNumber ebnConjugate = new ComplexNumber(-3, 2);

            // Do the opposite (complex -> string) with the same numbers
            String fromComplex1 = expected1.ToString();
            String fromComplex2 = expected2.ToString();

            // Run the tests
            ComplexNumber.AssertEqualty(expected1, result1);
            ComplexNumber.AssertEqualty(expected2, result2);
            Assert.AreEqual(bPositive, fromComplex1);
            Assert.AreEqual(bNegative, fromComplex2);
            ComplexNumber.AssertEqualty(ebpConjugate, bpConjugate);
            ComplexNumber.AssertEqualty(ebnConjugate, bnConjugate);
        }
        public void ConjugateTest()
        {
            _testVar = new ComplexNumber(2, 2);

            _testVar = _testVar.Conjugate();
            Assert.Equal(2, _testVar.RealPart);
            Assert.Equal(-2, _testVar.ImagPart);
        }
示例#6
0
    public ComplexNumber Div(ComplexNumber other)
    {
        var con = other.Conjugate();

        var numFirsts = _real * con._real;
        var numOuters = _real * con._imaginary;
        var numInners = _imaginary * con._real;
        var numLasts  = _imaginary * con._imaginary * -1;

        var domFirsts = other._real * con._real;
        var domOuters = other._real * con._imaginary; // not required as it cancels out domInners
        var domInners = other._imaginary * con._real; // see above
        var domLasts  = other._imaginary * con._imaginary * -1;

        var numA = numFirsts + numLasts;
        var numB = numOuters + numInners;
        var dom  = domFirsts + domLasts;

        return(new ComplexNumber(numA / dom, numB / dom));
    }
示例#7
0
 public void ConjugateAndNegate()
 {
     Assert.IsTrue(ComplexEqual(Complex.Conjugate(complex1), ComplexNumber.Conjugate(complexNumber1)));
     Assert.IsTrue(ComplexEqual(Complex.Negate(complex1), ComplexNumber.Negate(complexNumber1)));
 }
示例#8
0
    public ComplexNumber Div(ComplexNumber other)
    {
        double denominator = other.imaginary * other.imaginary + other.real * other.real;

        return(Mul(other.Conjugate()) / denominator);
    }