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  
18  package org.hipparchus.ode.nonstiff;
19  
20  import org.hipparchus.ode.EquationsMapper;
21  import org.hipparchus.ode.ODEStateAndDerivative;
22  
23  /**
24   * This class implements a simple Euler integrator for Ordinary
25   * Differential Equations.
26   *
27   * <p>The Euler algorithm is the simplest one that can be used to
28   * integrate ordinary differential equations. It is a simple inversion
29   * of the forward difference expression :
30   * <code>f'=(f(t+h)-f(t))/h</code> which leads to
31   * <code>f(t+h)=f(t)+hf'</code>. The interpolation scheme used for
32   * dense output is the linear scheme already used for integration.</p>
33   *
34   * <p>This algorithm looks cheap because it needs only one function
35   * evaluation per step. However, as it uses linear estimates, it needs
36   * very small steps to achieve high accuracy, and small steps lead to
37   * numerical errors and instabilities.</p>
38   *
39   * <p>This algorithm is almost never used and has been included in
40   * this package only as a comparison reference for more useful
41   * integrators.</p>
42   *
43   * @see MidpointIntegrator
44   * @see ClassicalRungeKuttaIntegrator
45   * @see GillIntegrator
46   * @see ThreeEighthesIntegrator
47   * @see LutherIntegrator
48   */
49  
50  public class EulerIntegrator extends RungeKuttaIntegrator {
51  
52      /** Name of integration scheme. */
53      public static final String METHOD_NAME = "Euler";
54  
55      /** Simple constructor.
56       * Build an Euler integrator with the given step.
57       * @param step integration step
58       */
59      public EulerIntegrator(final double step) {
60          super(METHOD_NAME, step);
61      }
62  
63      /** {@inheritDoc} */
64      @Override
65      public double[] getC() {
66          return new double[0];
67      }
68  
69      /** {@inheritDoc} */
70      @Override
71      public double[][] getA() {
72          return new double[0][];
73      }
74  
75      /** {@inheritDoc} */
76      @Override
77      public double[] getB() {
78          return new double[] { 1 };
79      }
80  
81      /** {@inheritDoc} */
82      @Override
83      protected EulerStateInterpolator
84          createInterpolator(final boolean forward, double[][] yDotK,
85                             final ODEStateAndDerivative globalPreviousState,
86                             final ODEStateAndDerivative globalCurrentState,
87                             final EquationsMapper mapper) {
88          return new EulerStateInterpolator(forward, yDotK,
89                                           globalPreviousState, globalCurrentState,
90                                           globalPreviousState, globalCurrentState,
91                                           mapper);
92      }
93  
94  }