我需要计算近似的拉格朗日多项式在点,点为了.
我尝试了以下代码:
import java.math.*;
import org.apache.commons.math3.analysis.polynomials.PolynomialFunctionLagrangeForm;
public class interpolation {
public static void main(String[] args) {
// TODO Auto-generated method stub
int N = 100;
double [] X = new double [N+1];
double [] Y = new double [N+1];
// Here we give the computer the points:
for(int k=0; k<=N ;k++){
double a = k/(N*N*1.0);
double b = Math.exp(a);
X[k]=a;
Y[k]=b;
}
// here we build the polynomial
PolynomialFunctionLagrangeForm pol = new PolynomialFunctionLagrangeForm( X , Y );
double [] P = pol.getCoefficients();
// here we print the polynomial
for(int i=P.length -1 ;i >= 0;i--){
System.out.print( P[i] + " ");
}
}
}
它为但对(它根本不像泰勒展开式)。我想帮助更精确地计算这个多项式。非常感谢你。