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.util.FastMath; 26 27 /** 28 * This class is used in the junit tests for the ODE integrators. 29 30 * <p>This specific problem is the following differential equation : 31 * <pre> 32 * y' = t^3 - t y 33 * </pre> 34 * with the initial condition y (0) = 0. The solution of this equation 35 * is the following function : 36 * <pre> 37 * y (t) = t^2 + 2 (exp (- t^2 / 2) - 1) 38 * </pre> 39 * </p> 40 41 */ 42 public class TestProblem2 extends TestProblemAbstract { 43 44 /** 45 * Simple constructor. 46 */ 47 public TestProblem2() { 48 super(0.0, new double[] { 0.0 }, 1.0, new double[] { 1.0 }); 49 } 50 51 @Override 52 public double[] doComputeDerivatives(double t, double[] y) { 53 54 // compute the derivatives 55 final double[] yDot = new double[getDimension()]; 56 for (int i = 0; i < getDimension(); ++i) { 57 yDot[i] = t * (t * t - y[i]); 58 } 59 return yDot; 60 61 } 62 63 @Override 64 public double[] computeTheoreticalState(double t) { 65 final double[] y = new double[getDimension()]; 66 double t2 = t * t; 67 double c = t2 + 2 * (FastMath.exp (-0.5 * t2) - 1); 68 for (int i = 0; i < getDimension(); ++i) { 69 y[i] = c; 70 } 71 return y; 72 } 73 74 }