UnivariateDerivative.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 java.io.Serializable;

  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 <T> the type of the function derivative
  23.  * @since 1.7
  24.  */
  25. public abstract class UnivariateDerivative<T extends UnivariateDerivative<T>>
  26.     implements Derivative<T>, Serializable, Comparable<T> {

  27.     /** Serializable UID. */
  28.     private static final long serialVersionUID = 20200519L;

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

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

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

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

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

  64. }