本文整理汇总了Java中org.apache.commons.math3.ode.FirstOrderDifferentialEquations类的典型用法代码示例。如果您正苦于以下问题:Java FirstOrderDifferentialEquations类的具体用法?Java FirstOrderDifferentialEquations怎么用?Java FirstOrderDifferentialEquations使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FirstOrderDifferentialEquations类属于org.apache.commons.math3.ode包,在下文中一共展示了FirstOrderDifferentialEquations类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testTooLargeFirstStep
import org.apache.commons.math3.ode.FirstOrderDifferentialEquations; //导入依赖的package包/类
@Test
public void testTooLargeFirstStep() {
RungeKuttaIntegrator integ = new ClassicalRungeKuttaIntegrator(0.5);
final double start = 0.0;
final double end = 0.001;
FirstOrderDifferentialEquations equations = new FirstOrderDifferentialEquations() {
public int getDimension() {
return 1;
}
public void computeDerivatives(double t, double[] y, double[] yDot) {
Assert.assertTrue(t >= FastMath.nextAfter(start, Double.NEGATIVE_INFINITY));
Assert.assertTrue(t <= FastMath.nextAfter(end, Double.POSITIVE_INFINITY));
yDot[0] = -100.0 * y[0];
}
};
integ.integrate(equations, start, new double[] { 1.0 }, end, new double[1]);
}
示例2: testTooLargeFirstStep
import org.apache.commons.math3.ode.FirstOrderDifferentialEquations; //导入依赖的package包/类
@Test
public void testTooLargeFirstStep()
throws DimensionMismatchException, NumberIsTooSmallException,
MaxCountExceededException, NoBracketingException {
AdaptiveStepsizeIntegrator integ =
new DormandPrince853Integrator(0, Double.POSITIVE_INFINITY, Double.NaN, Double.NaN);
final double start = 0.0;
final double end = 0.001;
FirstOrderDifferentialEquations equations = new FirstOrderDifferentialEquations() {
public int getDimension() {
return 1;
}
public void computeDerivatives(double t, double[] y, double[] yDot) {
Assert.assertTrue(t >= FastMath.nextAfter(start, Double.NEGATIVE_INFINITY));
Assert.assertTrue(t <= FastMath.nextAfter(end, Double.POSITIVE_INFINITY));
yDot[0] = -100.0 * y[0];
}
};
integ.setStepSizeControl(0, 1.0, 1.0e-6, 1.0e-8);
integ.integrate(equations, start, new double[] { 1.0 }, end, new double[1]);
}
示例3: testTooLargeFirstStep
import org.apache.commons.math3.ode.FirstOrderDifferentialEquations; //导入依赖的package包/类
@Test
public void testTooLargeFirstStep()
throws DimensionMismatchException, NumberIsTooSmallException,
MaxCountExceededException, NoBracketingException {
AdaptiveStepsizeIntegrator integ =
new GraggBulirschStoerIntegrator(0, Double.POSITIVE_INFINITY, Double.NaN, Double.NaN);
final double start = 0.0;
final double end = 0.001;
FirstOrderDifferentialEquations equations = new FirstOrderDifferentialEquations() {
public int getDimension() {
return 1;
}
public void computeDerivatives(double t, double[] y, double[] yDot) {
Assert.assertTrue(t >= FastMath.nextAfter(start, Double.NEGATIVE_INFINITY));
Assert.assertTrue(t <= FastMath.nextAfter(end, Double.POSITIVE_INFINITY));
yDot[0] = -100.0 * y[0];
}
};
integ.setStepSizeControl(0, 1.0, 1.0e-6, 1.0e-8);
integ.integrate(equations, start, new double[] { 1.0 }, end, new double[1]);
}
示例4: value
import org.apache.commons.math3.ode.FirstOrderDifferentialEquations; //导入依赖的package包/类
@Override
public double[] value(double[] point) throws IllegalArgumentException {
for (int i = 0; i < parameters.size(); i++) {
if (!initParameters.contains(parameters.get(i))) {
parser.setVarValue(parameters.get(i), point[i]);
}
}
FirstOrderIntegrator integratorInstance = integrator.createIntegrator();
List<Double> result = new ArrayList<>();
for (int i = 0; i < timeValues.size(); i++) {
FirstOrderDifferentialEquations f = MathUtils.createDiffEquations(parser, functions, dependentVariables,
timeVariable, variableFunctions.get(i));
double[] values = new double[formulas.size()];
for (int j = 0; j < formulas.size(); j++) {
values[j] = initValues.get(j) != null ? initValues.get(j)
: point[parameters.indexOf(initParameters.get(i).get(j))];
}
result.add(values[dependentIndex]);
for (int j = 1; j < timeValues.get(i).size(); j++) {
integratorInstance.integrate(f, timeValues.get(i).get(j - 1), values, timeValues.get(i).get(j), values);
result.add(values[dependentIndex]);
}
}
return Doubles.toArray(result);
}
示例5: value
import org.apache.commons.math3.ode.FirstOrderDifferentialEquations; //导入依赖的package包/类
@Override
public double[] value(double[] point) throws IllegalArgumentException {
for (int i = 0; i < parameters.size(); i++) {
if (!initParameters.contains(parameters.get(i))) {
parser.setVarValue(parameters.get(i), point[i]);
}
}
double[] values = new double[formulas.size()];
for (int i = 0; i < formulas.size(); i++) {
values[i] = initValues.get(i) != null ? initValues.get(i)
: point[parameters.indexOf(initParameters.get(i))];
}
FirstOrderDifferentialEquations f = MathUtils.createDiffEquations(parser, functions, dependentVariables,
timeVariable, variableFunctions);
FirstOrderIntegrator integratorInstance = integrator.createIntegrator();
List<Double> result = new ArrayList<>();
result.add(values[dependentIndex]);
for (int i = 1; i < timeValues.size(); i++) {
integratorInstance.integrate(f, timeValues.get(i - 1), values, timeValues.get(i), values);
result.add(values[dependentIndex]);
}
return Doubles.toArray(result);
}
示例6: getDiffPoints
import org.apache.commons.math3.ode.FirstOrderDifferentialEquations; //导入依赖的package包/类
public static double[] getDiffPoints(Map<String, Double> parserConstants, Map<String, String> functions,
Map<String, Double> initValues, Map<String, String> initParameters,
Map<String, List<Double>> conditionLists, String dependentVariable,
Map<String, Double> independentVariables, String varX, double[] valuesX, IntegratorFactory integrator,
InterpolationFactory interpolator) throws ParseException {
DiffFunctionConf function = new DiffFunctionConf(parserConstants, functions, initValues, initParameters,
conditionLists, dependentVariable, independentVariables, varX, valuesX, integrator, interpolator);
double[] result = diffResults.getIfPresent(function);
if (result != null) {
return result;
}
List<ASTNode> fs = new ArrayList<>();
List<String> valueVariables = new ArrayList<>();
double[] values = new double[functions.size()];
Parser parser = new Parser();
parserConstants.forEach((constant, value) -> parser.setVarValue(constant, value));
int index = 0;
for (Map.Entry<String, String> entry : functions.entrySet()) {
String var = entry.getKey();
fs.add(parser.parse(entry.getValue()));
valueVariables.add(var);
values[index++] = initValues.containsKey(var) ? initValues.get(var)
: parserConstants.get(initParameters.get(var));
}
Map<String, UnivariateFunction> variableFunctions = MathUtils.createInterpolationFunctions(conditionLists, varX,
interpolator);
FirstOrderDifferentialEquations f = MathUtils.createDiffEquations(parser, fs, valueVariables, varX,
variableFunctions);
FirstOrderIntegrator instance = integrator.createIntegrator();
double diffValue = conditionLists.get(varX).get(0);
int depIndex = valueVariables.indexOf(dependentVariable);
double[] valuesY = new double[valuesX.length];
for (int i = 0; i < valuesX.length; i++) {
if (valuesX[i] == diffValue) {
valuesY[i] = values[depIndex];
} else if (valuesX[i] > diffValue) {
instance.integrate(f, diffValue, values, valuesX[i], values);
diffValue = valuesX[i];
valuesY[i] = values[depIndex];
} else {
valuesY[i] = Double.NaN;
}
}
diffResults.put(function, valuesY);
return valuesY;
}