/** * Computes (a+b)^2 in two different ways and compares the result. * For correct results, a and b should be integers. * * @param a * @param b */ private static void CheckBinomialSquare(double a, double b) { // binomial square var add = new DD(a); var bdd = new DD(b); var aPlusb = add.Add(bdd); var abSq = aPlusb.Multiply(aPlusb); // System.out.println("(a+b)^2 = " + abSq); // expansion var a2DD = add.Multiply(add); var b2DD = bdd.Multiply(bdd); var ab = add.Multiply(bdd); var sum = b2DD.Add(ab).Add(ab); // System.out.println("2ab+b^2 = " + sum); var diff = abSq.Subtract(a2DD); // System.out.println("(a+b)^2 - a^2 = " + diff); var delta = diff.Subtract(sum); Console.WriteLine("\nA = " + a + ", B = " + b); Console.WriteLine("[DD] 2ab+b^2 = " + sum + " (a+b)^2 - a^2 = " + diff + " delta = " + delta); PrintBinomialSquareDouble(a, b); var isSame = diff.Equals(sum); Assert.IsTrue(isSame); var isDeltaZero = delta.IsZero; Assert.IsTrue(isDeltaZero); }
private static void CheckBinomial2(double a, double b) { // binomial product var add = new DD(a); var bdd = new DD(b); var aPlusb = add.Add(bdd); var aSubb = add.Subtract(bdd); var abProd = aPlusb.Multiply(aSubb); // System.out.println("(a+b)^2 = " + abSq); // expansion var a2DD = add.Multiply(add); var b2DD = bdd.Multiply(bdd); // System.out.println("2ab+b^2 = " + sum); // this should equal b^2 var diff = abProd.Subtract(a2DD).Negate(); // System.out.println("(a+b)^2 - a^2 = " + diff); var delta = diff.Subtract(b2DD); Console.WriteLine("\nA = " + a + ", B = " + b); Console.WriteLine("[DD] (a+b)(a-b) = " + abProd + " -((a^2 - b^2) - a^2) = " + diff + " delta = " + delta); // printBinomialSquareDouble(a,b); var isSame = diff.Equals(b2DD); Assert.IsTrue(isSame); var isDeltaZero = delta.IsZero; Assert.IsTrue(isDeltaZero); }
private static void CheckAddMult2(DD dd) { DD sum = dd.Add(dd); DD prod = dd.Multiply(new DD(2.0)); CheckErrorBound("AddMult2", sum, prod, 0.0); }
public CStatTestFixture(int slotMax) { for (int i = 0; i < slotMax; i++) { SerialNo.Add(""); ResultName.Add(""); ResultId.Add(0); Result.Add(0); Value.Add(""); Volt.Add(0); Cur.Add(0); DD.Add(""); } }
/// <summary> /// Computes the arctangent based on the Taylor series expansion /// <para/> /// arctan(x) = x - x^3 / 3 + x^5 / 5 - x^7 / 7 + ... /// </summary> /// <param name="x">The argument</param> /// <returns>An approximation to the arctangent of the input</returns> private static DD ArcTan(DD x) { var t = x; var t2 = t.Sqr(); var at = new DD(0.0); var two = new DD(2.0); var k = 0; var d = new DD(1.0); var sign = 1; while (t.ToDoubleValue() > DD.Epsilon) { k++; at = sign < 0 ? at.Subtract(t.Divide(d)) : at.Add(t.Divide(d)); d = d.Add(two); t = t.Multiply(t2); sign = -sign; } Console.WriteLine("Computed DD.atan(): " + at + " Math.atan = " + Math.Atan(x.ToDoubleValue())); return(at); }
/// <summary> /// Computes the arctangent based on the Taylor series expansion /// <para/> /// arctan(x) = x - x^3 / 3 + x^5 / 5 - x^7 / 7 + ... /// </summary> /// <param name="x">The argument</param> /// <returns>An approximation to the arctangent of the input</returns> private static DD ArcTan(DD x) { var t = x; var t2 = t.Sqr(); var at = new DD(0.0); var two = new DD(2.0); var k = 0; var d = new DD(1.0); var sign = 1; while (t.ToDoubleValue() > DD.Epsilon) { k++; at = sign < 0 ? at.Subtract(t.Divide(d)) : at.Add(t.Divide(d)); d = d.Add(two); t = t.Multiply(t2); sign = -sign; } Console.WriteLine("Computed DD.atan(): " + at + " Math.atan = " + Math.Atan(x.ToDoubleValue())); return at; }
private static void CheckBinomial2(double a, double b) { // binomial product var add = new DD(a); var bdd = new DD(b); var aPlusb = add.Add(bdd); var aSubb = add.Subtract(bdd); var abProd = aPlusb.Multiply(aSubb); // System.out.println("(a+b)^2 = " + abSq); // expansion var a2DD = add.Multiply(add); var b2DD = bdd.Multiply(bdd); // System.out.println("2ab+b^2 = " + sum); // this should equal b^2 var diff = abProd.Subtract(a2DD).Negate(); // System.out.println("(a+b)^2 - a^2 = " + diff); var delta = diff.Subtract(b2DD); Console.WriteLine("\nA = " + a + ", B = " + b); Console.WriteLine("[DD] (a+b)(a-b) = " + abProd + " -((a^2 - b^2) - a^2) = " + diff + " delta = " + delta); // printBinomialSquareDouble(a,b); var isSame = diff.Equals(b2DD); Assert.IsTrue(isSame); var isDeltaZero = delta.IsZero; Assert.IsTrue(isDeltaZero); }
/** * Computes (a+b)^2 in two different ways and compares the result. * For correct results, a and b should be integers. * * @param a * @param b */ private static void CheckBinomialSquare(double a, double b) { // binomial square var add = new DD(a); var bdd = new DD(b); var aPlusb = add.Add(bdd); var abSq = aPlusb.Multiply(aPlusb); // System.out.println("(a+b)^2 = " + abSq); // expansion var a2DD = add.Multiply(add); var b2DD = bdd.Multiply(bdd); var ab = add.Multiply(bdd); var sum = b2DD.Add(ab).Add(ab); // System.out.println("2ab+b^2 = " + sum); var diff = abSq.Subtract(a2DD); // System.out.println("(a+b)^2 - a^2 = " + diff); var delta = diff.Subtract(sum); Console.WriteLine("\nA = " + a + ", B = " + b); Console.WriteLine("[DD] 2ab+b^2 = " + sum + " (a+b)^2 - a^2 = " + diff + " delta = " + delta); PrintBinomialSquareDouble(a, b); var isSame = diff.Equals(sum); Assert.IsTrue(isSame); var isDeltaZero = delta.IsZero; Assert.IsTrue(isDeltaZero); }
private static void CheckAddMult2(DD dd) { DD sum = dd.Add(dd); DD prod = dd.Multiply(new DD(2.0)); CheckErrorBound("AddMult2", sum, prod, 0.0); }