Ejemplo n.º 1
0
void spolint (const float *xa, const float *ya, int_t n,
	            float x,         float *y,  float *dy)
{
  register int_t ns  = 1;
#if  defined(__uxp__) || defined(_SX)
  float            dif = (float) fabs (x - xa[1]),
#else
  float            dif = fabsf(x - xa[1]),
#endif
                   *c  = svector(1, n),
                   *d  = svector(1, n);
  register int_t i, m;
  float            den, dift, ho, hp, w;

  for (i = 1; i <= n; i++) {
#if  defined(__uxp__) || defined(_SX)
    if ((dift = (float) fabs  (x - xa[1])) < dif) {
#else
    if ((dift =         fabsf (x - xa[i])) < dif) {
#endif
      ns  = i;
      dif = dift;
    }
    c[i] = ya[i];
    d[i] = ya[i];
  }
    
  *y = ya[ns--];
  for (m = 1; m < n; m++) {
    for (i = 1; i <= n - m; i++) {
      ho = xa[i] - x;
      hp = xa[i+m] -x;
      w  = c[i+1] - d[i];
      if( (den = ho-hp) == 0.0F)
	message("spolint()", "two x values the same (within roundoff)", ERROR);
      den  = w  / den;
      d[i] = hp * den;
      c[i] = ho * den;
    }
    *y += (*dy=((ns<<1) < (n-m) ? c[ns+1] : d[ns--]));
  }

  freeSvector (c, 1);
  freeSvector (d, 1);
}
Ejemplo n.º 2
0
void sspline (integer n, float yp1, float ypn, const float* x, const float* y,
                                                                     float* y2)
{
  register integer i, k;
  float            h  = x[1] - x[0], 
                   *u = svector(0, n-2);
  float            p, qn, sig, un, hh;

  if (yp1 > 0.99e30)
    y2[0] = u[0] = 0.0F;
  else {
    y2[0] = -0.5F;
    u [0] = (3.0F / h) * ((y[1]-y[0]) / h - yp1);
  }

  for (i = 1; i < n-1; i++) {
    hh     = 1. / (x[i+1] - x[i-1]);
    sig    = h * hh;
    p      = sig * y2[i-1] + 2.;
    y2[i]  = (sig - 1.) / p;
    u [i]  = (y[i] - y[i-1]) / h;
    u [i]  = (y[i+1] - y[i]) / (h = x[i+1]-x[i]) - u[i];
    u [i]  = (6.0F * u[i] * hh - sig * u[i-1])/p;
  }

  if (ypn > 0.99e30)
    qn = un = 0.0F;
  else {
    qn = 0.5F;
    un = (3.0F / h)*(ypn - (y[n-1]-y[n-2])/h);
  }

  y2[n-1] = (un - qn * u[n-2]) / (qn * y2[n-2] + 1.);
  for (k = n-2; k; k--) y2[k] = y2[k] * y2[k+1] + u[k];

  freeSvector(u, 0);
}