/********************************************************** * * BiCubicSplinePartialDerivative.java * * Class for performing an interpolation on the tabulated * function y = f(x1,x2) using a natural bicubic spline * Assumes second derivatives at end points = 0 (natural spine) * Calculates the interpolated value of y and its first derivative with respect to x1 * * Primarily for use with BiCubicSplineFirstDerivative * * WRITTEN BY: Dr Michael Thomas Flanagan * * DATE: 12 January 2010 - modified version of BiCubicSpline (2003 - 2008) * UPDATE: * * DOCUMENTATION: * See Michael Thomas Flanagan's Java library on-line web page: * http://www.ee.ucl.ac.uk/~mflanaga/java/BiCubicSplineFirstDerivative.html * http://www.ee.ucl.ac.uk/~mflanaga/java/ * * Copyright (c) 2003 - 2010 Michael Thomas Flanagan * * PERMISSION TO COPY: * * Permission to use, copy and modify this software and its documentation for NON-COMMERCIAL purposes is granted, without fee, * provided that an acknowledgement to the author, Dr Michael Thomas Flanagan at www.ee.ucl.ac.uk/~mflanaga, appears in all copies * and associated documentation or publications. * * Redistributions of the source code of this source code, or parts of the source codes, must retain the above copyright notice, this list of conditions * and the following disclaimer and requires written permission from the Michael Thomas Flanagan: * * Redistribution in binary form of all or parts of this class must reproduce the above copyright notice, this list of conditions and * the following disclaimer in the documentation and/or other materials provided with the distribution and requires written permission from the Michael Thomas Flanagan: * * Dr Michael Thomas Flanagan makes no representations about the suitability or fitness of the software for any or for a particular purpose. * Dr Michael Thomas Flanagan shall not be liable for any damages suffered as a result of using, modifying or distributing this software * or its derivatives. * ***************************************************************************************/ package flanagan.interpolation; import flanagan.math.Fmath; public class BiCubicSplinePartialDerivative{ private int nPoints = 0; // no. of x1 tabulated points private int mPoints = 0; // no. of x2 tabulated points private double[][] y = null; // y=f(x1,x2) tabulated function private double[] x1 = null; // x1 in tabulated function f(x1,x2) private double[] x2 = null; // x2 in tabulated function f(x1,x2) private double[] xMin = new double[2]; // minimum values of x1 and x2 private double[] xMax = new double[2]; // maximum values of x1 and x2 private CubicSpline csn[] = null; // nPoints array of CubicSpline instances private CubicSpline csm = null; // CubicSpline instance private boolean derivCalculated = false; // = true when the first called cubic spline derivatives have been calculated private boolean averageIdenticalAbscissae = false; // if true: the the ordinate values for identical abscissae are averaged // If false: the abscissae values are separated by 0.001 of the total abscissae range; private static double potentialRoundingError = 5e-15; // potential rounding error used in checking wheter a value lies within the interpolation bounds (static value) private static boolean roundingCheck = true; // = true: points outside the interpolation bounds by less than the potential rounding error rounded to the bounds limit (static value) // Constructor // Constructor with data arrays initialised to arrays x and y public BiCubicSplinePartialDerivative(double[] x1, double[] x2, double[][] y){ this.nPoints=x1.length; this.mPoints=x2.length; if(this.nPoints!=y.length)throw new IllegalArgumentException("Arrays x1 and y-row are of different length " + this.nPoints + " " + y.length); if(this.mPoints!=y[0].length)throw new IllegalArgumentException("Arrays x2 and y-column are of different length "+ this.mPoints + " " + y[0].length); if(this.nPoints<3 || this.mPoints<3)throw new IllegalArgumentException("The data matrix must have a minimum size of 3 X 3"); this.csm = new CubicSpline(this.nPoints); this.csn = CubicSpline.oneDarray(this.nPoints, this.mPoints); this.x1 = new double[this.nPoints]; this.x2 = new double[this.mPoints]; this.y = new double[this.nPoints][this.mPoints]; for(int i=0; i