EulerIntegrator.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.ode.nonstiff;

  18. import org.hipparchus.ode.EquationsMapper;
  19. import org.hipparchus.ode.ODEStateAndDerivative;
  20. import org.hipparchus.ode.nonstiff.interpolators.EulerStateInterpolator;

  21. /**
  22.  * This class implements a simple Euler integrator for Ordinary
  23.  * Differential Equations.
  24.  *
  25.  * <p>The Euler algorithm is the simplest one that can be used to
  26.  * integrate ordinary differential equations. It is a simple inversion
  27.  * of the forward difference expression :
  28.  * <code>f'=(f(t+h)-f(t))/h</code> which leads to
  29.  * <code>f(t+h)=f(t)+hf'</code>. The interpolation scheme used for
  30.  * dense output is the linear scheme already used for integration.</p>
  31.  *
  32.  * <p>This algorithm looks cheap because it needs only one function
  33.  * evaluation per step. However, as it uses linear estimates, it needs
  34.  * very small steps to achieve high accuracy, and small steps lead to
  35.  * numerical errors and instabilities.</p>
  36.  *
  37.  * <p>This algorithm is almost never used and has been included in
  38.  * this package only as a comparison reference for more useful
  39.  * integrators.</p>
  40.  *
  41.  * @see MidpointIntegrator
  42.  * @see ClassicalRungeKuttaIntegrator
  43.  * @see GillIntegrator
  44.  * @see ThreeEighthesIntegrator
  45.  * @see LutherIntegrator
  46.  */

  47. public class EulerIntegrator extends FixedStepRungeKuttaIntegrator {

  48.     /** Name of integration scheme. */
  49.     public static final String METHOD_NAME = "Euler";

  50.     /** Simple constructor.
  51.      * Build an Euler integrator with the given step.
  52.      * @param step integration step
  53.      */
  54.     public EulerIntegrator(final double step) {
  55.         super(METHOD_NAME, step);
  56.     }

  57.     /** {@inheritDoc} */
  58.     @Override
  59.     public double[] getC() {
  60.         return new double[0];
  61.     }

  62.     /** {@inheritDoc} */
  63.     @Override
  64.     public double[][] getA() {
  65.         return new double[0][];
  66.     }

  67.     /** {@inheritDoc} */
  68.     @Override
  69.     public double[] getB() {
  70.         return new double[] { 1 };
  71.     }

  72.     /** {@inheritDoc} */
  73.     @Override
  74.     protected EulerStateInterpolator createInterpolator(final boolean forward, final double[][] yDotK,
  75.                                                         final ODEStateAndDerivative globalPreviousState,
  76.                                                         final ODEStateAndDerivative globalCurrentState,
  77.                                                         final EquationsMapper mapper) {
  78.         return new EulerStateInterpolator(forward, yDotK, globalPreviousState, globalCurrentState,
  79.                                          globalPreviousState, globalCurrentState, mapper);
  80.     }

  81. }