1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.nabla.differences;
18  
19  import org.apache.commons.nabla.Polynomial;
20  import org.apache.commons.nabla.ReferenceFunction;
21  import org.apache.commons.nabla.differences.FiniteDifferencesDifferentiator;
22  import org.apache.commons.nabla.differences.FourPointsScheme;
23  
24  public class FourPointsSchemeTest extends AbstractFiniteDifferencesTest {
25  
26      public void testApproximatePolynomialDifferentiation() {
27  
28          ReferenceFunction reference = Polynomial.randomPolynomial(random, 5);
29          checkValues(reference, 0.1, -1.0, 1.0, 100, 3.0e-4);
30          checkOrder(reference, Math.PI, 0.05, 0.1, 100, 7.261, 1.0e-3);
31  
32          reference = Polynomial.randomPolynomial(random, 6);
33          checkValues(reference, 0.1, -1.0, 1.0, 100, 2.0e-3);
34          checkOrder(reference, Math.PI, 0.05, 0.1, 10, 131.682, 1.0e-3);
35  
36      }
37  
38      public void testHugeDifferentialsFunction() {
39          ReferenceFunction reference = hugeDifferentialsFunction();
40          checkValues(reference, 0.05, 0.3, 0.7, 100, 0.005);
41          checkOrder(reference, 0.5, 0.01, 0.02, 10, 130.548, 0.084);
42      }
43  
44      protected FiniteDifferencesDifferentiator buildDifferentiator(double h) {
45          return new FourPointsScheme(h);
46      }
47  
48      protected int getOrder() {
49          return 4;
50      }
51  
52  }