You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by lu...@apache.org on 2012/08/10 14:18:12 UTC

svn commit: r1371681 - /commons/proper/math/trunk/src/test/java/org/apache/commons/math3/analysis/differentiation/DerivativeStructureTest.java

Author: luc
Date: Fri Aug 10 12:18:12 2012
New Revision: 1371681

URL: http://svn.apache.org/viewvc?rev=1371681&view=rev
Log:
New test for sin and cos derivatives.

Modified:
    commons/proper/math/trunk/src/test/java/org/apache/commons/math3/analysis/differentiation/DerivativeStructureTest.java

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/analysis/differentiation/DerivativeStructureTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/analysis/differentiation/DerivativeStructureTest.java?rev=1371681&r1=1371680&r2=1371681&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/analysis/differentiation/DerivativeStructureTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/analysis/differentiation/DerivativeStructureTest.java Fri Aug 10 12:18:12 2012
@@ -174,7 +174,7 @@ public class DerivativeStructureTest {
     }
 
     @Test
-    public void testPower() {
+    public void testPow() {
         for (int maxOrder = 1; maxOrder < 5; ++maxOrder) {
             for (int n = 0; n < 10; ++n) {
 
@@ -426,6 +426,40 @@ public class DerivativeStructureTest {
     }
 
     @Test
+    public void testSinCos() {
+        double epsilon = 5.0e-16;
+        for (int maxOrder = 0; maxOrder < 6; ++maxOrder) {
+            for (double x = 0.1; x < 1.2; x += 0.001) {
+                DerivativeStructure dsX = new DerivativeStructure(1, maxOrder, 0, x);
+                DerivativeStructure sin = dsX.sin();
+                DerivativeStructure cos = dsX.cos();
+                double s = FastMath.sin(x);
+                double c = FastMath.cos(x);
+                for (int n = 0; n <= maxOrder; ++n) {
+                    switch (n % 4) {
+                    case 0 :
+                        Assert.assertEquals( s, sin.getPartialDerivative(n), epsilon);
+                        Assert.assertEquals( c, cos.getPartialDerivative(n), epsilon);
+                        break;
+                    case 1 :
+                        Assert.assertEquals( c, sin.getPartialDerivative(n), epsilon);
+                        Assert.assertEquals(-s, cos.getPartialDerivative(n), epsilon);
+                        break;
+                    case 2 :
+                        Assert.assertEquals(-s, sin.getPartialDerivative(n), epsilon);
+                        Assert.assertEquals(-c, cos.getPartialDerivative(n), epsilon);
+                        break;
+                    default :
+                        Assert.assertEquals(-c, sin.getPartialDerivative(n), epsilon);
+                        Assert.assertEquals( s, cos.getPartialDerivative(n), epsilon);
+                        break;
+                    }
+                }
+            }
+        }
+    }
+
+    @Test
     public void testTangentDefinition() {
         double[] epsilon = new double[] { 5.0e-16, 2.0e-15, 3.0e-14, 5.0e-13, 2.0e-11 };
         for (int maxOrder = 0; maxOrder < 5; ++maxOrder) {