计算 100 点的拉格朗日多项式?

计算科学 数值分析 插值 多项式
2021-12-29 01:11:53

我需要计算近似的拉格朗日多项式ex101点,点k1012为了k{0,1,2100}.

我尝试了以下代码:

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] + "    ");
         }


    }

}

它为N=5,10但对N=50,100(它根本不像泰勒展开式)。我想帮助更精确地计算这个多项式。非常感谢你。

0个回答
没有发现任何回复~