Example: The cubic spline interpolant to noisy data

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.
using System;
using Imsl.Math;
using Imsl.Stat;

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 + System.Math.Pow(3.0 * (x[k] - 1.0), 4));
		}
		
		//	Seed the random number generator
		Imsl.Stat.Random rn = new Imsl.Stat.Random(1234579);
		rn.Multiplier = 16807;
		
		//	Contaminate the data
		for (int i = 0; i < n; i++)
		{
			y[i] += 2.0 * (float) rn.NextDouble() - 1.0;
		}
		
		//	Smooth the data
		CsSmooth cs = new CsSmooth(x, y);
		double csv = cs.Eval(0.3010);
		Console.Out.WriteLine("The computed cubic spline value at " +
			                  "point .3010 is " + csv);
	}
}

Output

The computed cubic spline value at point .3010 is 0.0101201298963992

Link to C# source.