21 void initSpline(
int[] x,
int[] y,
int n) {
25 double[] u =
new double[n];
26 for (i=1; i<n-1; i++) {
28 sig = ((double) x[i]-x[i-1]) / ((double) x[i+1] - x[i-1]);
29 p = sig * y2[i-1] + 2.0;
30 y2[i] = (sig-1.0) / p;
31 u[i] = (((double) y[i+1]-y[i]) / (x[i+1]-x[i])) -
32 (((double) y[i]-y[i-1]) / (x[i]-x[i-1]));
33 u[i] = (6.0 * u[i]/ (x[i+1]-x[i-1]) - sig*u[i-1]) / p;
36 y2[n-1] = (un-qn*u[n-2]) / (qn*y2[n-2]+1.0);
37 for (k=n-2; k>=0; k--)
38 y2[k] = y2[k]*y2[k+1]+u[k];
42 public double evalSpline(
int x[],
int y[],
int n,
double xp) {
49 if (x[k] > xp) khi = k;
55 if (h==0.0)
return (0.0);
60 if(y2==null)
return (0.0);
62 return (a*y[klo] + b*y[khi] + ((a*a*a-a)*y2[klo] +(b*b*b-b)*y2[khi])