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
9
* http://www.apache.org/licenses/LICENSE-2.0
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.
18
package org.apache.commons.math.ode;
21
* This class is used in the junit tests for the ODE integrators.
23
* <p>This specific problem is the following differential equation :
25
* y1'' = -y1/r^3 y1 (0) = 1-e y1' (0) = 0
26
* y2'' = -y2/r^3 y2 (0) = 0 y2' (0) =sqrt((1+e)/(1-e))
27
* r = sqrt (y1^2 + y2^2), e = 0.9
29
* This is a two-body problem in the plane which can be solved by
38
extends TestProblemAbstract {
43
/** theoretical state */
48
* @param e eccentricity
50
public TestProblem3(double e) {
53
double[] y0 = { 1 - e, 0, 0, Math.sqrt((1+e)/(1-e)) };
54
setInitialConditions(0.0, y0);
55
setFinalConditions(20.0);
56
double[] errorScale = { 1.0, 1.0, 1.0, 1.0 };
57
setErrorScale(errorScale);
58
y = new double[y0.length];
64
public TestProblem3() {
70
* @param problem problem to copy
72
public TestProblem3(TestProblem3 problem) {
75
y = (double[]) problem.y.clone();
80
* @return a copy of the instance
82
public Object clone() {
83
return new TestProblem3(this);
86
public void doComputeDerivatives(double t, double[] y, double[] yDot) {
89
double r2 = y[0] * y[0] + y[1] * y[1];
90
double invR3 = 1 / (r2 * Math.sqrt(r2));
92
// compute the derivatives
95
yDot[2] = -invR3 * y[0];
96
yDot[3] = -invR3 * y[1];
100
public double[] computeTheoreticalState(double t) {
102
// solve Kepler's equation
107
double f2 = e * Math.sin(E);
109
double f1 = 1 - e * Math.cos(E);
110
double f12 = f1 + f1;
111
corr = f0 * f12 / (f1 * f12 - f0 * f2);
114
} while (Math.abs(corr) > 1.0e-12);
116
double cosE = Math.cos(E);
117
double sinE = Math.sin(E);
120
y[1] = Math.sqrt(1 - e * e) * sinE;
121
y[2] = -sinE / (1 - e * cosE);
122
y[3] = Math.sqrt(1 - e * e) * cosE / (1 - e * cosE);