View Javadoc
1   /*
2    * Licensed to the Hipparchus project 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 Hipparchus project 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    *      https://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.hipparchus.analysis.differentiation;
18  
19  import java.io.Serializable;
20  
21  import org.hipparchus.exception.LocalizedCoreFormats;
22  import org.hipparchus.exception.MathIllegalArgumentException;
23  
24  /** Abstract class representing both the value and the differentials of a function.
25   * @param <T> the type of the function derivative
26   * @since 1.7
27   */
28  public abstract class UnivariateDerivative<T extends UnivariateDerivative<T>>
29      implements Derivative<T>, Serializable, Comparable<T> {
30  
31      /** Serializable UID. */
32      private static final long serialVersionUID = 20200519L;
33  
34      /** Empty constructor.
35       * <p>
36       * This constructor is not strictly necessary, but it prevents spurious
37       * javadoc warnings with JDK 18 and later.
38       * </p>
39       * @since 3.0
40       */
41      public UnivariateDerivative() { // NOPMD - unnecessary constructor added intentionally to make javadoc happy
42          // nothing to do
43      }
44  
45      /** {@inheritDoc} */
46      @Override
47      public int getFreeParameters() {
48          return 1;
49      }
50  
51      /** {@inheritDoc} */
52      @Override
53      public double getPartialDerivative(final int ... orders) throws MathIllegalArgumentException {
54          if (orders.length != 1) {
55              throw new MathIllegalArgumentException(LocalizedCoreFormats.DIMENSIONS_MISMATCH,
56                                                     orders.length, 1);
57          }
58          return getDerivative(orders[0]);
59      }
60  
61      /** Get a derivative from the univariate derivative.
62       * @param n derivation order (must be between 0 and {@link #getOrder()}, both inclusive)
63       * @return n<sup>th</sup> derivative
64       * @exception MathIllegalArgumentException if n is
65       * either negative or strictly larger than {@link #getOrder()}
66       */
67      public abstract double getDerivative(int n) throws MathIllegalArgumentException;
68  
69      /** Convert the instance to a {@link DerivativeStructure}.
70       * @return derivative structure with same value and derivative as the instance
71       */
72      public abstract DerivativeStructure toDerivativeStructure();
73  
74  }