package com.imsl.test.example.math; import java.text.*; import com.imsl.math.*; /** *
* Spline2DInterpolate Example 1: Computes a tensor-product spline * interpolant.
* * A tensor-product spline interpolant to the function $$f(x,y) = x^{3} + y^2$$ * is computed. The values of the interpolant and the error on a \(4 \times 4\) * grid are displayed. * * @see Code * @see Output */ public class Spline2DInterpolateEx1 { private static double F(double x, double y) { return (x * x * x + y * y); } public static void main(String args[]) { int nData = 11; int outData = 2; double[][] fData = new double[nData][nData]; double[] xData = new double[nData]; double[] yData = new double[nData]; double x, y, z; // Set up grid for (int i = 0; i < nData; i++) { xData[i] = yData[i] = (double) i / ((double) (nData - 1)); } for (int i = 0; i < nData; i++) { for (int j = 0; j < nData; j++) { fData[i][j] = F(xData[i], yData[j]); } } // Compute tensor-product interpolant Spline2DInterpolate spline = new Spline2DInterpolate(xData, yData, fData); NumberFormat nf = NumberFormat.getInstance(); nf.setMaximumFractionDigits(4); nf.setMinimumFractionDigits(4); // Print results System.out.println(" x y F(x, y) " + "Interpolant Error"); for (int i = 0; i < outData; i++) { x = (double) i / (double) (outData); for (int j = 0; j < outData; j++) { y = (double) j / (double) (outData); z = spline.value(x, y); System.out.println(nf.format(x) + " " + nf.format(y) + " " + nf.format(F(x, y)) + " " + nf.format(z) + " " + nf.format(Math.abs(F(x, y) - z))); } } } }