source: src/main/java/agents/anac/y2015/agentBuyogV2/flanagan/interpolation/BiCubicSplineFast.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: 4.3 KB
Line 
1/**********************************************************
2*
3* BiCubicSplineFast.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* Stripped down version of BiCubicSpline - all data checks have been removed for faster running
9*
10* WRITTEN BY: Dr Michael Thomas Flanagan
11*
12* DATE: 26 December 2009 (Stripped down version of BiCubicSpline: May 2002 - 31 October 2009)
13* UPDATE:
14*
15* DOCUMENTATION:
16* See Michael Thomas Flanagan's Java library on-line web page:
17* http://www.ee.ucl.ac.uk/~mflanaga/java/BiCubicSplineFast.html
18* http://www.ee.ucl.ac.uk/~mflanaga/java/
19*
20* Copyright (c) 2002 - 2009 Michael Thomas Flanagan
21*
22* PERMISSION TO COPY:
23*
24* Permission to use, copy and modify this software and its documentation for NON-COMMERCIAL purposes is granted, without fee,
25* provided that an acknowledgement to the author, Dr Michael Thomas Flanagan at www.ee.ucl.ac.uk/~mflanaga, appears in all copies
26* and associated documentation or publications.
27*
28* 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
29* and the following disclaimer and requires written permission from the Michael Thomas Flanagan:
30*
31* Redistribution in binary form of all or parts of this class must reproduce the above copyright notice, this list of conditions and
32* the following disclaimer in the documentation and/or other materials provided with the distribution and requires written permission from the Michael Thomas Flanagan:
33*
34* Dr Michael Thomas Flanagan makes no representations about the suitability or fitness of the software for any or for a particular purpose.
35* Dr Michael Thomas Flanagan shall not be liable for any damages suffered as a result of using, modifying or distributing this software
36* or its derivatives.
37*
38***************************************************************************************/
39
40package agents.anac.y2015.agentBuyogV2.flanagan.interpolation;
41
42public class BiCubicSplineFast{
43
44 private int nPoints = 0; // no. of x1 tabulated points
45 private int mPoints = 0; // no. of x2 tabulated points
46 private double[][] y = null; // y=f(x1,x2) tabulated function
47 private double[] x1 = null; // x1 in tabulated function f(x1,x2)
48 private double[] x2 = null; // x2 in tabulated function f(x1,x2)
49 private CubicSplineFast csn[] = null; // nPoints array of CubicSpline instances
50 private CubicSplineFast csm = null; // CubicSpline instance
51
52
53 // Constructor
54 // Constructor with data arrays initialised to arrays x and y
55 public BiCubicSplineFast(double[] x1, double[] x2, double[][] y){
56 this.nPoints=x1.length;
57 this.mPoints=x2.length;
58
59 this.csm = new CubicSplineFast(this.nPoints);
60 this.csn = CubicSplineFast.oneDarray(this.nPoints, this.mPoints);
61 this.x1 = new double[this.nPoints];
62 this.x2 = new double[this.mPoints];
63 this.y = new double[this.nPoints][this.mPoints];
64 for(int i=0; i<this.nPoints; i++){
65 this.x1[i]=x1[i];
66 }
67 for(int j=0; j<this.mPoints; j++){
68 this.x2[j]=x2[j];
69 }
70 for(int i =0; i<this.nPoints; i++){
71 for(int j=0; j<this.mPoints; j++){
72 this.y[i][j]=y[i][j];
73 }
74 }
75
76 double[] yTempn = new double[mPoints];
77
78 for(int i=0; i<this.nPoints; i++){
79 for(int j=0; j<mPoints; j++)yTempn[j]=y[i][j];
80 this.csn[i].resetData(x2,yTempn);
81 this.csn[i].calcDeriv();
82 }
83 }
84
85 // METHOD
86
87 // Returns an interpolated value of y for a value of x
88 // from a tabulated function y=f(x1,x2)
89 public double interpolate(double xx1, double xx2){
90
91 double[] yTempm = new double[this.nPoints];
92
93 for (int i=0;i<this.nPoints;i++){
94 yTempm[i]=this.csn[i].interpolate(xx2);
95 }
96 this.csm.resetData(x1,yTempm);
97 return this.csm.interpolate(xx1);
98 }
99}
100
Note: See TracBrowser for help on using the repository browser.