New test for sin and cos derivatives.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1371681 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
add45005fc
commit
be1632f3e3
|
@ -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) {
|
||||
|
||||
|
@ -425,6 +425,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 };
|
||||
|
|
Loading…
Reference in New Issue