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