Inquiry of interpolations and exterior methods often used in Commons Math

Commons Math is a commonly used Java library that contains many methods for interpolation and Extraporation.The interpolation is the process of the approximate value of the unknown point based on the known data point, and the external push is based on the trend of the known data point to predict the value of the point of the data range. Commons Math provides a variety of interpolation methods, including linear interpolation, Laglangine interpolation, Newton's interpolation, and strip interpolation.The following will explore several commonly used methods. 1. Linear interpolation: Linear interpolation is the simplest interpolation method. It assumes that the relationship between data points is linear.Commons Math provides a linear interpolation in the Commons Math to perform linear interpolations.The following is an example code that uses linear interpolations: import org.apache.commons.math3.analysis.interpolation.LinearInterpolator; import org.apache.commons.math3.analysis.interpolation.UnivariateInterpolator; import org.apache.commons.math3.analysis.polynomials.PolynomialSplineFunction; public class LinearInterpolationExample { public static void main(String[] args) { // Knowing data points double[] x = {1.0, 2.0, 3.0, 4.0}; double[] y = {2.0, 4.0, 6.0, 8.0}; // Create a linear interpolation UnivariateInterpolator interpolator = new LinearInterpolator(); PolynomialSplineFunction function = interpolator.interpolate(x, y); // Use the linear interpolation to calculate the unknown point of the unknown point double unknownX = 2.5; double interpolatedY = function.value(unknownX); System.out.println("Interpolated value at x = " + unknownX + " is: " + interpolatedY); } } 2. Laglangine interpolation: Laglangine interpolation is a polynomial interpolation method, which can propose a curve with any number of intentions.Commons Math provides the Lagrangeinterpotor class to execute the Lagrangor interpolation.Here are a sample code that uses the Raglan daily interpolation: import org.apache.commons.math3.analysis.interpolation.LagrangeInterpolator; import org.apache.commons.math3.analysis.polynomials.PolynomialFunctionLagrangeForm; public class LagrangeInterpolationExample { public static void main(String[] args) { // Knowing data points double[] x = {1.0, 2.0, 3.0, 4.0}; double[] y = {2.0, 4.0, 6.0, 8.0}; // Create a Lagram daily interpolation device LagrangeInterpolator interpolator = new LagrangeInterpolator(); PolynomialFunctionLagrangeForm function = interpolator.interpolate(x, y); // Use the Lagrangri plug device to calculate the unknown point double unknownX = 2.5; double interpolatedY = function.value(unknownX); System.out.println("Interpolated value at x = " + unknownX + " is: " + interpolatedY); } } 3. Sample interpolation: Sample interpolation is a method that combines data by using multiple low -number polynomials in the interpolation interpolation range. It can get smoother curves.Commons Math provides the SplineInterpotor class to execute sample interpolations.Here are a sample code that uses a sample interpolation: import org.apache.commons.math3.analysis.interpolation.SplineInterpolator; import org.apache.commons.math3.analysis.polynomials.PolynomialSplineFunction; public class SplineInterpolationExample { public static void main(String[] args) { // Knowing data points double[] x = {1.0, 2.0, 3.0, 4.0}; double[] y = {2.0, 4.0, 6.0, 8.0}; // Create a sample interpolation device SplineInterpolator interpolator = new SplineInterpolator(); PolynomialSplineFunction function = interpolator.interpolate(x, y); // Use the sample interpolation device to calculate the unknown point double unknownX = 2.5; double interpolatedY = function.value(unknownX); System.out.println("Interpolated value at x = " + unknownX + " is: " + interpolatedY); } } In addition to the interpolation method, the Commons Math also provides a variety of external methods, which can infer the value beyond the point of the data range according to the trend of the known data point.For specific use methods, please refer to the official documentation and example code of Commons Math.