FieldUnivariateDerivative.java

  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. import org.hipparchus.CalculusFieldElement;
  19. import org.hipparchus.exception.LocalizedCoreFormats;
  20. import org.hipparchus.exception.MathIllegalArgumentException;

  21. /** Abstract class representing both the value and the differentials of a function.
  22.  * @param <S> the type of the field elements
  23.  * @param <T> the type of the function derivative
  24.  * @since 1.7
  25.  */
  26. public abstract class FieldUnivariateDerivative<S extends CalculusFieldElement<S>, T extends FieldUnivariateDerivative<S, T>>
  27.     implements FieldDerivative<S, T> {

  28.     /** Empty constructor.
  29.      * <p>
  30.      * This constructor is not strictly necessary, but it prevents spurious
  31.      * javadoc warnings with JDK 18 and later.
  32.      * </p>
  33.      * @since 3.0
  34.      */
  35.     protected FieldUnivariateDerivative() { // NOPMD - unnecessary constructor added intentionally to make javadoc happy
  36.         // nothing to do
  37.     }

  38.     /** {@inheritDoc} */
  39.     @Override
  40.     public int getFreeParameters() {
  41.         return 1;
  42.     }

  43.     /** {@inheritDoc} */
  44.     @Override
  45.     public S getPartialDerivative(final int ... orders) throws MathIllegalArgumentException {
  46.         if (orders.length != 1) {
  47.             throw new MathIllegalArgumentException(LocalizedCoreFormats.DIMENSIONS_MISMATCH,
  48.                                                    orders.length, 1);
  49.         }
  50.         return getDerivative(orders[0]);
  51.     }

  52.     /** Get a derivative from the univariate derivative.
  53.      * @param n derivation order (must be between 0 and {@link #getOrder()}, both inclusive)
  54.      * @return n<sup>th</sup> derivative
  55.      * @exception MathIllegalArgumentException if n is
  56.      * either negative or strictly larger than {@link #getOrder()}
  57.      */
  58.     public abstract S getDerivative(int n) throws MathIllegalArgumentException;

  59.     /** Convert the instance to a {@link DerivativeStructure}.
  60.      * @return derivative structure with same value and derivative as the instance
  61.      */
  62.     public abstract FieldDerivativeStructure<S> toDerivativeStructure();

  63. }