本文整理汇总了Java中org.apache.commons.math3.analysis.polynomials.PolynomialSplineFunction.getPolynomials方法的典型用法代码示例。如果您正苦于以下问题:Java PolynomialSplineFunction.getPolynomials方法的具体用法?Java PolynomialSplineFunction.getPolynomials怎么用?Java PolynomialSplineFunction.getPolynomials使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.math3.analysis.polynomials.PolynomialSplineFunction
的用法示例。
在下文中一共展示了PolynomialSplineFunction.getPolynomials方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: verifyConsistency
import org.apache.commons.math3.analysis.polynomials.PolynomialSplineFunction; //导入方法依赖的package包/类
/**
* Verifies that interpolating polynomials satisfy consistency requirement:
* adjacent polynomials must agree through two derivatives at knot points
*/
protected void verifyConsistency(PolynomialSplineFunction f, double x[])
{
PolynomialFunction polynomials[] = f.getPolynomials();
for (int i = 1; i < x.length - 2; i++) {
// evaluate polynomials and derivatives at x[i + 1]
Assert.assertEquals(polynomials[i].value(x[i +1] - x[i]), polynomials[i + 1].value(0), 0.1);
Assert.assertEquals(polynomials[i].derivative().value(x[i +1] - x[i]),
polynomials[i + 1].derivative().value(0), 0.5);
Assert.assertEquals(polynomials[i].polynomialDerivative().derivative().value(x[i +1] - x[i]),
polynomials[i + 1].polynomialDerivative().derivative().value(0), 0.5);
}
}
示例2: addLinearExtrapolationToBorders
import org.apache.commons.math3.analysis.polynomials.PolynomialSplineFunction; //导入方法依赖的package包/类
public static PolynomialSplineFunction addLinearExtrapolationToBorders(PolynomialSplineFunction spline, int minFrame, int maxFrame) {
PolynomialFunction[] polynomials = spline.getPolynomials();
double[] knots = spline.getKnots();
boolean addToBeginning = knots[0] != minFrame;
boolean addToEnd = knots[knots.length - 1] != maxFrame;
int sizeIncrease = 0 + (addToBeginning ? 1 : 0) + (addToEnd ? 1 : 0);
if(!addToBeginning && !addToEnd) {
return spline; //do nothing
}
//construct new knots and polynomial arrays
double[] newKnots = new double[knots.length + sizeIncrease];
PolynomialFunction[] newPolynomials = new PolynomialFunction[polynomials.length + sizeIncrease];
//add to beginning
if(addToBeginning) {
//add knot
newKnots[0] = minFrame;
System.arraycopy(knots, 0, newKnots, 1, knots.length);
//add function
double derivativeAtFirstKnot = polynomials[0].derivative().value(0);
double valueAtFirstKnot = spline.value(knots[0]);
PolynomialFunction beginningFunction = new PolynomialFunction(new double[]{valueAtFirstKnot - (knots[0] - minFrame) * derivativeAtFirstKnot, derivativeAtFirstKnot});
newPolynomials[0] = beginningFunction;
System.arraycopy(polynomials, 0, newPolynomials, 1, polynomials.length);
} else {
System.arraycopy(knots, 0, newKnots, 0, knots.length);
System.arraycopy(polynomials, 0, newPolynomials, 0, polynomials.length);
}
//add to end
if(addToEnd) {
//add knot
newKnots[newKnots.length - 1] = maxFrame;
//add function
double derivativeAtLastKnot = polynomials[polynomials.length - 1].polynomialDerivative().value(knots[knots.length - 1] - knots[knots.length - 2]);
double valueAtLastKnot = spline.value(knots[knots.length - 1]);
PolynomialFunction endFunction = new PolynomialFunction(new double[]{valueAtLastKnot, derivativeAtLastKnot});
newPolynomials[newPolynomials.length - 1] = endFunction;
}
return new PolynomialSplineFunction(newKnots, newPolynomials);
}