package com.imsl.test.example.math; import com.imsl.math.*; import com.imsl.stat.*; /** *
* Computes a smooth cubic spline on noisy data using an "optimized" smoothing * parameter value.
* * A cubic spline interpolant to noisy data is computed using cross-validation * to estimate the smoothing parameter. The value of the spline at point 0.3010 * is printed. * * @see Code * @see Output * */ public class CsSmoothEx1 { public static void main(String args[]) { int n = 300; double x[] = new double[n]; double y[] = new double[n]; for (int k = 0; k < n; k++) { x[k] = (3.0 * k) / (n - 1); y[k] = 1.0 / (0.1 + Math.pow(3.0 * (x[k] - 1.0), 4)); } // Seed the random number generator Random rn = new Random(); rn.setSeed(1234579L); rn.setMultiplier(16807); // Contaminate the data for (int i = 0; i < n; i++) { y[i] += 2.0 * rn.nextFloat() - 1.0; } // Smooth the data CsSmooth cs = new CsSmooth(x, y); double csv = cs.value(0.3010); System.out.println("The computed cubic spline value at point .3010 is " + csv); } }