View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) 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 ASF 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  /*
19   * This is not the original file distributed by the Apache Software Foundation
20   * It has been modified by the Hipparchus project
21   */
22  
23  package org.hipparchus.ode;
24  
25  /**
26   * This class is used in the junit tests for the ODE integrators.
27  
28   * <p>This specific problem is the following differential equation :
29   * <pre>
30   *    y' = 3x^5 - y
31   * </pre>
32   * when the initial condition is y(0) = -360, the solution of this
33   * equation degenerates to a simple quintic polynomial function :
34   * <pre>
35   *   y (t) = 3x^5 - 15x^4 + 60x^3 - 180x^2 + 360x - 360
36   * </pre>
37   * </p>
38  
39   */
40  public class TestProblem6 extends TestProblemAbstract {
41  
42      /**
43       * Simple constructor.
44       */
45      public TestProblem6() {
46          super(0.0, new double[] { -360.0 }, 1.0, new double[] { 1.0 });
47      }
48  
49      @Override
50      public double[] doComputeDerivatives(double t, double[] y) {
51  
52          final  double[] yDot = new double[getDimension()];
53  
54          // compute the derivatives
55          double t2 = t  * t;
56          double t4 = t2 * t2;
57          double t5 = t4 * t;
58          for (int i = 0; i < getDimension(); ++i) {
59              yDot[i] = 3 * t5 - y[i];
60          }
61  
62          return yDot;
63  
64      }
65  
66      @Override
67      public double[] computeTheoreticalState(double t) {
68          final double[] y = new double[getDimension()];
69          for (int i = 0; i < getDimension(); ++i) {
70              y[i] = ((((3 * t - 15) * t + 60) * t - 180) * t + 360) * t - 360;
71          }
72          return y;
73      }
74  
75  }