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  import org.hipparchus.Field;
26  import org.hipparchus.CalculusFieldElement;
27  import org.hipparchus.util.MathArrays;
28  
29  /**
30   * This class is used in the junit tests for the ODE integrators.
31   * <p>This is the same as problem 1 except integration is done
32   * backward in time</p>
33   * @param <T> the type of the field elements
34   */
35  public class TestFieldProblem5<T extends CalculusFieldElement<T>>
36      extends TestFieldProblemAbstract<T> {
37  
38      /**
39       * Simple constructor.
40       * @param field field to which elements belong
41       */
42      public TestFieldProblem5(Field<T> field) {
43          super(convert(field, 0.0),
44                convert(field, 1.0, 0.1),
45                convert(field, -4.0),
46                convert(field, 1.0, 1.0));
47      }
48  
49      @Override
50      public T[] doComputeDerivatives(T t, T[] y) {
51  
52          final T[] yDot = MathArrays.buildArray(getField(), getDimension());
53  
54          // compute the derivatives
55          for (int i = 0; i < getDimension(); ++i) {
56              yDot[i] = y[i].negate();
57          }
58  
59          return yDot;
60  
61      }
62  
63      @Override
64      public T[] computeTheoreticalState(T t) {
65          final FieldODEState<T> s0 = getInitialState();
66          final T[] y0 = s0.getPrimaryState();
67          final T[] y = MathArrays.buildArray(getField(), getDimension());
68          T c = s0.getTime().subtract(t).exp();
69          for (int i = 0; i < getDimension(); ++i) {
70              y[i] = c.multiply(y0[i]);
71          }
72          return y;
73      }
74  
75  }