source: src/main/java/agents/anac/y2015/agentBuyogV2/flanagan/interpolation/BiCubicSplinePartialDerivative.java

Last change on this file was 127, checked in by Wouter Pasman, 6 years ago

#41 ROLL BACK of rev.126 . So this version is equal to rev. 125

File size: 8.3 KB
Line 
1/**********************************************************
2*
3* BiCubicSplinePartialDerivative.java
4*
5* Class for performing an interpolation on the tabulated
6* function y = f(x1,x2) using a natural bicubic spline
7* Assumes second derivatives at end points = 0 (natural spine)
8* Calculates the interpolated value of y and its first derivative with respect to x1
9*
10* Primarily for use with BiCubicSplineFirstDerivative
11*
12* WRITTEN BY: Dr Michael Thomas Flanagan
13*
14* DATE: 12 January 2010 - modified version of BiCubicSpline (2003 - 2008)
15* UPDATE:
16*
17* DOCUMENTATION:
18* See Michael Thomas Flanagan's Java library on-line web page:
19* http://www.ee.ucl.ac.uk/~mflanaga/java/BiCubicSplineFirstDerivative.html
20* http://www.ee.ucl.ac.uk/~mflanaga/java/
21*
22* Copyright (c) 2003 - 2010 Michael Thomas Flanagan
23*
24* PERMISSION TO COPY:
25*
26* Permission to use, copy and modify this software and its documentation for NON-COMMERCIAL purposes is granted, without fee,
27* provided that an acknowledgement to the author, Dr Michael Thomas Flanagan at www.ee.ucl.ac.uk/~mflanaga, appears in all copies
28* and associated documentation or publications.
29*
30* 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
31* and the following disclaimer and requires written permission from the Michael Thomas Flanagan:
32*
33* Redistribution in binary form of all or parts of this class must reproduce the above copyright notice, this list of conditions and
34* the following disclaimer in the documentation and/or other materials provided with the distribution and requires written permission from the Michael Thomas Flanagan:
35*
36* Dr Michael Thomas Flanagan makes no representations about the suitability or fitness of the software for any or for a particular purpose.
37* Dr Michael Thomas Flanagan shall not be liable for any damages suffered as a result of using, modifying or distributing this software
38* or its derivatives.
39*
40***************************************************************************************/
41
42package agents.anac.y2015.agentBuyogV2.flanagan.interpolation;
43
44import agents.anac.y2015.agentBuyogV2.flanagan.math.Fmath;
45
46public class BiCubicSplinePartialDerivative{
47
48 private int nPoints = 0; // no. of x1 tabulated points
49 private int mPoints = 0; // no. of x2 tabulated points
50 private double[][] y = null; // y=f(x1,x2) tabulated function
51 private double[] x1 = null; // x1 in tabulated function f(x1,x2)
52 private double[] x2 = null; // x2 in tabulated function f(x1,x2)
53 private double[] xMin = new double[2]; // minimum values of x1 and x2
54 private double[] xMax = new double[2]; // maximum values of x1 and x2
55 private CubicSpline csn[] = null; // nPoints array of CubicSpline instances
56 private CubicSpline csm = null; // CubicSpline instance
57 private boolean derivCalculated = false; // = true when the first called cubic spline derivatives have been calculated
58 private boolean averageIdenticalAbscissae = false; // if true: the the ordinate values for identical abscissae are averaged
59 // If false: the abscissae values are separated by 0.001 of the total abscissae range;
60 private static double potentialRoundingError = 5e-15; // potential rounding error used in checking wheter a value lies within the interpolation bounds (static value)
61 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)
62
63
64 // Constructor
65 // Constructor with data arrays initialised to arrays x and y
66 public BiCubicSplinePartialDerivative(double[] x1, double[] x2, double[][] y){
67 this.nPoints=x1.length;
68 this.mPoints=x2.length;
69 if(this.nPoints!=y.length)throw new IllegalArgumentException("Arrays x1 and y-row are of different length " + this.nPoints + " " + y.length);
70 if(this.mPoints!=y[0].length)throw new IllegalArgumentException("Arrays x2 and y-column are of different length "+ this.mPoints + " " + y[0].length);
71 if(this.nPoints<3 || this.mPoints<3)throw new IllegalArgumentException("The data matrix must have a minimum size of 3 X 3");
72
73 this.csm = new CubicSpline(this.nPoints);
74 this.csn = CubicSpline.oneDarray(this.nPoints, this.mPoints);
75 this.x1 = new double[this.nPoints];
76 this.x2 = new double[this.mPoints];
77 this.y = new double[this.nPoints][this.mPoints];
78 for(int i=0; i<this.nPoints; i++){
79 this.x1[i]=x1[i];
80 }
81 this.xMin[0] = Fmath.minimum(this.x1);
82 this.xMax[0] = Fmath.maximum(this.x1);
83 for(int j=0; j<this.mPoints; j++){
84 this.x2[j]=x2[j];
85 }
86 this.xMin[1] = Fmath.minimum(this.x2);
87 this.xMax[1] = Fmath.maximum(this.x2);
88 for(int i =0; i<this.nPoints; i++){
89 for(int j=0; j<this.mPoints; j++){
90 this.y[i][j]=y[i][j];
91 }
92 }
93
94 double[] yTempn = new double[mPoints];
95
96 for(int i=0; i<this.nPoints; i++){
97 for(int j=0; j<mPoints; j++)yTempn[j]=y[i][j];
98 this.csn[i].resetData(x2,yTempn);
99 this.csn[i].calcDeriv();
100 }
101 this.derivCalculated = true;
102 }
103
104 // METHODS
105
106 // Reset rounding error check option
107 // Default option: points outside the interpolation bounds by less than the potential rounding error rounded to the bounds limit
108 // This method causes this check to be ignored and an exception to be thrown if any point lies outside the interpolation bounds
109 public static void noRoundingErrorCheck(){
110 BiCubicSplinePartialDerivative.roundingCheck = false;
111 CubicSpline.noRoundingErrorCheck();
112 }
113
114 // Reset potential rounding error value
115 // Default option: points outside the interpolation bounds by less than the potential rounding error rounded to the bounds limit
116 // The default value for the potential rounding error is 5e-15*times the 10^exponent of the value outside the bounds
117 // This method allows the 5e-15 to be reset
118 public static void potentialRoundingError(double potentialRoundingError){
119 BiCubicSplinePartialDerivative.potentialRoundingError = potentialRoundingError;
120 CubicSpline.potentialRoundingError(potentialRoundingError);
121 }
122
123 // Reset the default handing of identical abscissae with different ordinates
124 // from the default option of separating the two relevant abscissae by 0.001 of the range
125 // to avraging the relevant ordinates
126 public void averageIdenticalAbscissae(){
127 this.averageIdenticalAbscissae = true;
128 for(int i=0; i<this.csn.length; i++)this.csn[i].averageIdenticalAbscissae();
129 this.csm.averageIdenticalAbscissae();
130 }
131
132 // Get minimum limits
133 public double[] getXmin(){
134 return this.xMin;
135 }
136
137 // Get maximum limits
138 public double[] getXmax(){
139 return this.xMax;
140 }
141
142 // Get limits to x
143 public double[] getLimits(){
144 double[] limits = {xMin[0], xMax[0], xMin[1], xMax[1]};
145 return limits;
146 }
147
148 // Display limits to x
149 public void displayLimits(){
150 System.out.println(" ");
151 for(int i=0; i<2; i++){
152 System.out.println("The limits to the x array " + i + " are " + xMin[i] + " and " + xMax[i]);
153 }
154 System.out.println(" ");
155 }
156
157
158 // Returns an interpolated value of y for a value of x
159 // from a tabulated function y=f(x1,x2)
160 public double[] interpolate(double xx1, double xx2){
161
162 double[] yTempm = new double[this.nPoints];
163
164 for (int i=0;i<this.nPoints;i++){
165 yTempm[i]=this.csn[i].interpolate(xx2);
166 }
167 this.csm.resetData(x1,yTempm);
168 return this.csm.interpolate_for_y_and_dydx(xx1);
169 }
170}
171
Note: See TracBrowser for help on using the repository browser.