/// <summary> /// </summary> /// <param name="a"></param> /// <param name="b"></param> /// <param name="c"></param> /// <returns></returns> public static Complex[] QuadraticEquationEx(double a, double b, double c) { var discriminant = Math.Pow(b, 2) - 4 * a * c; var q = -(b + Math.Sign(b) * ComplexArithmetic.Sqrt(discriminant)) / 2; return(new[] { q / a, c / q }); }
public void ComplexNumberConstructorsWithZeroValuedParameters() { var compE = new Complex(21, 0); var compF = ComplexArithmetic.FromString("21"); Assert.IsTrue(compE == compF); }
public Form1() { InitializeComponent(); complexData1 = new ComplexData(); complexData2 = new ComplexData(); complexAnswer = new ComplexData(); complexArithmetic = new ComplexArithmetic(); }
public void TestIfMulIsEqualToComplexOperator() { var z1 = new Complex(1.6859, 0.3902); var z2 = new Complex(3.51896, -0.458); var w1 = z1 * z2; var w2 = ComplexArithmetic.Multiply(z1, z2); Assert.IsTrue(w1.ApproximatelyEquals(w2, Epsilon)); }
public void TestIfPowIntInFasterThanPow() { const int iter = 250000; var z = new Complex(1.6859, 0.3902); var averageIntTime = BenchmarkUtil.Benchmark(() => { ComplexArithmetic.PowInt(z, 10); }, iter); var averageCpTime = BenchmarkUtil.Benchmark(() => { Complex.Pow(z, 10); }, iter); Assert.IsTrue(averageIntTime < averageCpTime); }
public void ComplexNumberConstructorsWithNonZeroValuedParameters() { var compA = new Complex(21, 7); var compB = ComplexArithmetic.FromString("21+7i"); Assert.IsTrue(compA == compB); var compC = new Complex(21, -7); var compD = ComplexArithmetic.FromString("21-7i"); Assert.IsTrue(compC == compD); }
public static Complex[] QuadraticEquation(double a, double b, double c) { // only real solutions for the moment var discriminant = Math.Pow(b, 2) - 4 * a * c; // x1 results wrong value. //ComplexNumber x1 = ((ComplexNumber)(-B) + ComplexOperation.Sqrt(discriminant)) / (2 * (ComplexNumber)A); //ComplexNumber x2 = (-B - ComplexOperation.Sqrt(discriminant)) / (2 * A); //return new ComplexNumber[] { x1, x2 }; //return new Vector((decimal)x1, (decimal)x2); var q = -(b + Math.Sign(b) * ComplexArithmetic.Sqrt(discriminant)) / 2; return(new[] { q / a, c / q }); }
public void TestSqrt() { var z = new Complex(1.961570561, 0.3901806440); var w = ComplexArithmetic.Sqrt(z); Assert.IsTrue(z.ApproximatelyEquals(w * w, Epsilon)); z = new Complex(-1.961570561, 0.3901806440); w = ComplexArithmetic.Sqrt(z); Assert.IsTrue(z.ApproximatelyEquals(w * w, Epsilon)); z = new Complex(-1.961570561, -0.3901806440); w = ComplexArithmetic.Sqrt(z); Assert.IsTrue(z.ApproximatelyEquals(w * w, Epsilon)); z = new Complex(1.961570561, -0.3901806440); w = ComplexArithmetic.Sqrt(z); Assert.IsTrue(z.ApproximatelyEquals(w * w, Epsilon)); }