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
32 * <p>This specific problem is the following differential equation :
33 * <pre>
34 * y' = t^3 - t y
35 * </pre>
36 * with the initial condition y (0) = 0. The solution of this equation
37 * is the following function :
38 * <pre>
39 * y (t) = t^2 + 2 (exp (- t^2 / 2) - 1)
40 * </pre>
41 * </p>
42
43 * @param <T> the type of the field elements
44 */
45 public class TestFieldProblem2<T extends CalculusFieldElement<T>>
46 extends TestFieldProblemAbstract<T> {
47
48 /**
49 * Simple constructor.
50 * @param field field to which elements belong
51 */
52 public TestFieldProblem2(Field<T> field) {
53 super(convert(field, 0.0),
54 convert(field, new double[] { 0.0 }),
55 convert(field, 1.0),
56 convert(field, new double[] { 1.0 }));
57 }
58
59 @Override
60 public T[] doComputeDerivatives(T t, T[] y) {
61
62 final T[] yDot = MathArrays.buildArray(getField(), getDimension());
63 // compute the derivatives
64 for (int i = 0; i < getDimension(); ++i) {
65 yDot[i] = t.multiply(t.multiply(t).subtract(y[i]));
66 }
67
68 return yDot;
69
70 }
71
72 @Override
73 public T[] computeTheoreticalState(T t) {
74 final T[] y = MathArrays.buildArray(getField(), getDimension());
75 T t2 = t.multiply(t);
76 T c = t2.add(t2.multiply(-0.5).exp().subtract(1).multiply(2));
77 for (int i = 0; i < getDimension(); ++i) {
78 y[i] = c;
79 }
80 return y;
81 }
82
83 }