Created
April 30, 2011 15:29
-
-
Save adrianp/949750 to your computer and use it in GitHub Desktop.
Java implementation of Aitken's Algorithm (scheme) for determining Newton's Divided Diffences
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* @param x the array of abscissae | |
* @param y the array of ordinates | |
* @return the top elements of the Divided Difference Table used when | |
* calculating Newton's Devided Differences | |
*/ | |
public static double[] aitken(double[] x, double[] y) { | |
int n = x.length; | |
double[] dividedDifferences = y.clone(); | |
for(int i=1; i<n; i++) { | |
for(int j=n-1; j>0; j--) { | |
if(j-i>=0) { | |
dividedDifferences[j] = (dividedDifferences[j]-dividedDifferences[j-1])/(x[j]-x[j-i]); | |
} | |
} | |
} | |
return dividedDifferences; | |
} | |
/* | |
This Java method will return the top elements of the Divided Difference Table | |
used when calculating Newton's Devided Differences (see [1]). | |
This form can be used in other applications like polynomial interpolation [2,4] | |
(e.g., Lagrange Polynomial [3]). | |
More info: | |
[1] http://www.maths.lancs.ac.uk/~gilbert/m243a/node6.html | |
[2] http://en.wikipedia.org/wiki/Interpolation | |
[3] http://en.wikipedia.org/wiki/Lagrange_polynomial | |
[4] http://en.wikipedia.org/wiki/Divided_differences | |
Please notify me about any issues with this. | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment