/*
* Adapted from:
* https://apache.googlesource.com/commons-math/+/d40d9b48aee58eea159eaa27ee14654fefd7af04/src/main/java/org/apache/commons/math3/analysis/polynomials/PolynomialsUtils.java
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import org.apache.commons.math3.analysis.polynomials.*;
import org.apache.commons.math3.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
//import org.apache.commons.math3.analysis.polynomials.PolynomialFunction;
//import org.apache.commons.math3.analysis.polynomials.PolynomialsUtils;
import org.apache.commons.math3.fraction.BigFraction;
import org.apache.commons.math3.util.Combinatorics;
import org.apache.commons.math3.util.FastMath;
/**
* A collection of static methods that operate on or return polynomials.
*
* @version $Id$
* @since 2.0
*/
public class Hermite {
/** Coefficients for Hermite polynomials. */
private static final List Hermite
* polynomials are orthogonal polynomials.
* They can be defined by the following recurrence relations:
*
* H0(X) = 1
* H1(X) = 2X
* Hk+1(X) = 2X Hk(X) - 2k Hk-1(X)
*
Ps(x)
* whose values at point {@code x} will be the same as the those from the
* original polynomial P(x)
when computed at {@code x + shift}.
* Thus, if P(x) = Σi ai xi
,
* then
* *
Ps(x) |
* = Σi bi xi | *
* | = Σi ai (x + shift)i | *
bi
of the shifted
* polynomial.
*/
public static double[] shift(final double[] coefficients,
final double shift) {
final int dp1 = coefficients.length;
final double[] newCoefficients = new double[dp1];
// Pascal triangle.
final int[][] coeff = new int[dp1][dp1];
for (int i = 0; i < dp1; i++){
for(int j = 0; j <= i; j++){
coeff[i][j] = (int) CombinatoricsUtils.binomialCoefficient(i, j);
}
}
// First polynomial coefficient.
for (int i = 0; i < dp1; i++){
newCoefficients[0] += coefficients[i] * FastMath.pow(shift, i);
}
// Superior order.
final int d = dp1 - 1;
for (int i = 0; i < d; i++) {
for (int j = i; j < d; j++){
newCoefficients[i + 1] += coeff[j + 1][j - i] *
coefficients[j + 1] * FastMath.pow(shift, j - i);
}
}
return newCoefficients;
}
/** Get the coefficients array for a given degree.
* @param degree degree of the polynomial
* @param coefficients list where the computed coefficients are stored
* @param generator recurrence coefficients generator
* @return coefficients array
*/
private static PolynomialFunction buildPolynomial(final int degree,
final List