1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.nabla.forward;
18
19 import org.apache.commons.math3.analysis.UnivariateFunction;
20 import org.apache.commons.math3.analysis.differentiation.DerivativeStructure;
21 import org.apache.commons.math3.analysis.differentiation.UnivariateDifferentiableFunction;
22 import org.apache.commons.math3.util.FastMath;
23 import org.apache.commons.nabla.AbstractMathTest;
24 import org.apache.commons.nabla.DifferentiationException;
25 import org.junit.Assert;
26 import org.junit.Test;
27
28 public class AtanGeneratorTest extends AbstractMathTest {
29
30 @Test
31 public void testReference(){
32 checkReference(new ReferenceFunction() {
33 public double value(double t) { return FastMath.atan(t); }
34 public double firstDerivative(double t) { return 1 / (1 + t * t); }
35 }, -1.5, 1.5, 30, 0.0);
36 }
37
38 @Test
39 public void testSingularityPlus() throws DifferentiationException {
40 UnivariateDifferentiableFunction derivative =
41 new ForwardModeDifferentiator().differentiate(new UnivariateFunction() {
42 public double value(double t) { return FastMath.atan(t); }
43 });
44
45 double dPlus = derivative.value(new DerivativeStructure(1, 1, Double.POSITIVE_INFINITY, 1.0)).getPartialDerivative(1);
46 Assert.assertEquals(0, dPlus, 0);
47
48 double dMinus = derivative.value(new DerivativeStructure(1, 1, Double.POSITIVE_INFINITY, -1.0)).getPartialDerivative(1);
49 Assert.assertEquals(0, dMinus, 0);
50
51 }
52
53 @Test
54 public void testSingularityMinus() throws DifferentiationException {
55 UnivariateDifferentiableFunction derivative =
56 new ForwardModeDifferentiator().differentiate(new UnivariateFunction() {
57 public double value(double t) { return FastMath.atan(t); }
58 });
59
60 double dPlus = derivative.value(new DerivativeStructure(1, 1, Double.NEGATIVE_INFINITY, 1.0)).getPartialDerivative(1);
61 Assert.assertEquals(0, dPlus, 0);
62
63 double dMinus = derivative.value(new DerivativeStructure(1, 1, Double.NEGATIVE_INFINITY, -1.0)).getPartialDerivative(1);
64 Assert.assertEquals(0, dMinus, 0);
65
66 }
67
68 }