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