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' = 3x^5 - y 35 * </pre> 36 * when the initial condition is y(0) = -360, the solution of this 37 * equation degenerates to a simple quintic polynomial function : 38 * <pre> 39 * y (t) = 3x^5 - 15x^4 + 60x^3 - 180x^2 + 360x - 360 40 * </pre> 41 * </p> 42 43 * @param <T> the type of the field elements 44 */ 45 public class TestFieldProblem6<T extends CalculusFieldElement<T>> 46 extends TestFieldProblemAbstract<T> { 47 48 /** 49 * Simple constructor. 50 * @param field field to which elements belong 51 */ 52 public TestFieldProblem6(Field<T> field) { 53 super(convert(field, 0.0), 54 convert(field, new double[] { -360.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 64 // compute the derivatives 65 T t2 = t.multiply(t); 66 T t4 = t2.multiply(t2); 67 T t5 = t4.multiply(t); 68 for (int i = 0; i < getDimension(); ++i) { 69 yDot[i] = t5.multiply(3).subtract(y[i]); 70 } 71 72 return yDot; 73 74 } 75 76 @Override 77 public T[] computeTheoreticalState(T t) { 78 79 final T[] y = MathArrays.buildArray(getField(), getDimension()); 80 81 for (int i = 0; i < getDimension(); ++i) { 82 y[i] = t.multiply(3).subtract(15).multiply(t).add(60).multiply(t).subtract(180).multiply(t).add(360).multiply(t).subtract(360); 83 } 84 85 return y; 86 87 } 88 89 }