/* This example of the use of CubicInterpolation and of CubicSpline demonstrates interpolation within a data set of the refractive index of fused quartz tabulated as a function of wavelength. Michael T Flanagan 20 May 2002 Updated 29 April 2005, 4 February 2006 */ import flanagan.interpolation.*; public class CubicExampleTwo{ public static void main(String arg[]){ // Array of wavelengths (m) double[] wavelength = {185.0e-9, 214.0e-9, 275.0e-9, 361.0e-9, 509.0e-9, 589.0e-9, 656.0e-9}; // Array of corresponding refractive indices double[] refrindex = {1.57464, 1.53386, 1.49634, 1.47503, 1.4619, 1.4583, 1.4564}; // Create a CubicInterpolation instance and initialise it to the data stored in the arrays wavelength and refrindex // Numerical differencing on entered data CubicInterpolation ci1 =new CubicInterpolation(wavelength, refrindex, 0); // Create a CubicInterpolation instance and initialise it to the data stored in the arrays wavelength and refrindex // Numerical differencing on interpolated data CubicInterpolation ci2 =new CubicInterpolation(wavelength, refrindex, 1); // Create a CubicSpline instance and initialise it to the data stored in the arrays wavelength and refrindex CubicSpline cs =new CubicSpline(wavelength, refrindex); // First interpolation at a wavelength of 250 nm double x1 = 2.5e-7; double y1=ci1.interpolate(x1); System.out.println("Cubic interpolation (numerical differencing on entered data):"); System.out.println("The refractive index of fused quartz at " + x1*1.0e9 + " nm is "+ y1); double y2=ci2.interpolate(x1); System.out.println("Cubic interpolation (numerical differencing on interpolated data):"); System.out.println("The refractive index of fused quartz at " + x1*1.0e9 + " nm is "+ y2); double y3=cs.interpolate(x1); System.out.println("Cubic spline:"); System.out.println("The refractive index of fused quartz at " + x1*1.0e9 + " nm is "+ y3); System.out.println(); // Second interpolation at a wavelength of 590 nm x1 = 5.9e-7; y1=ci1.interpolate(x1); System.out.println("Cubic interpolation (numerical differencing on entered data):"); System.out.println("The refractive index of fused quartz at " + x1*1.0e9 + " nm is "+ y1); y2=ci2.interpolate(x1); System.out.println("Cubic interpolation (numerical differencing on interpolated data):"); System.out.println("The refractive index of fused quartz at " + x1*1.0e9 + " nm is "+ y2); y3=cs.interpolate(x1); System.out.println("Cubic spline:"); System.out.println("The refractive index of fused quartz at " + x1*1.0e9 + " nm is "+ y3); } }