public void TestAbsOnNegative() { ComplexNumber firstComplexNumber = new ComplexNumber(-2, -4); double excpectedResult = Math.Sqrt(Math.Pow(-2, 2) + Math.Pow(-4, 2)); Assert.AreEqual(excpectedResult, firstComplexNumber.Abs()); }
public void TestAbsOnZero() { ComplexNumber firstComplexNumber = new ComplexNumber(0, 0); double excpectedResult = Math.Sqrt(Math.Pow(0, 2) + Math.Pow(0, 2)); Assert.AreEqual(excpectedResult, firstComplexNumber.Abs()); }
public static RealNumber GetMaximumError(this ComplexNumber[] a, ComplexNumber[] b) { RealNumber maxerr = 0; for (int i = Math.Max(a.Length, b.Length); --i >= 0;) { maxerr = RealNumber.Max(maxerr, ComplexNumber.Abs(a[i] - b[i])); } return(maxerr); }
private static double Calculate(ComplexNumber c) { const int MaxIterations = 1000; const double MaxNorm = MaxValueExtent * MaxValueExtent; var iteration = 0; var z = new ComplexNumber(); do { z = z * z + c; iteration++; } while (z.Abs() < MaxNorm && iteration < MaxIterations); return(iteration < MaxIterations ? (double)iteration / MaxIterations : 0); }
public void Absolute_value_of_a_number_with_real_and_imaginary_part() { var sut = new ComplexNumber(3, 4); Assert.Equal(5, sut.Abs()); }
public void Absolute_value_of_a_purely_imaginary_number_with_negative_imaginary_part() { var sut = new ComplexNumber(0, -5); Assert.Equal(5, sut.Abs()); }
public void Absolute_value_of_a_negative_purely_real_number() { var sut = new ComplexNumber(-5, 0); Assert.Equal(5, sut.Abs()); }
public ComplexNumber Div(ComplexNumber other) { return(new ComplexNumber((R * other.R + I * other.I) / Math.Pow(other.Abs(), 2), (I * other.R - R * other.I) / Math.Pow(other.Abs(), 2))); }
public ComplexNumber Div(ComplexNumber other) => new ComplexNumber((real * other.real + imaginary * other.imaginary) / (other.Abs() * other.Abs()), (imaginary * other.real - real * other.imaginary) / (other.Abs() * other.Abs()));