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 Log10GeneratorTest extends AbstractMathTest {
29
30 @Test
31 public void testReference(){
32 checkReference(new ReferenceFunction() {
33 public double value(double t) { return FastMath.log10(t); }
34 public double firstDerivative(double t) { return 1 / (FastMath.log(10) * t); }
35 }, 0.1, 10, 50, 3.0e-16);
36 }
37
38 @Test
39 public void testSingularity() throws DifferentiationException {
40 UnivariateDifferentiableFunction derivative =
41 new ForwardModeDifferentiator().differentiate(new UnivariateFunction() {
42 public double value(double t) { return FastMath.log10(t); }
43 });
44
45 double dPlus = derivative.value(new DerivativeStructure(1, 1, 0.0, 1.0)).getPartialDerivative(1);
46 Assert.assertTrue(Double.isInfinite(dPlus));
47 Assert.assertTrue(dPlus > 0);
48
49 double dMinus = derivative.value(new DerivativeStructure(1, 1, 0.0, -1.0)).getPartialDerivative(1);
50 Assert.assertTrue(Double.isInfinite(dMinus));
51 Assert.assertTrue(dMinus < 0);
52
53 }
54
55 }