add numerical recipes library
This commit is contained in:
20
lib/nr/ansi/recipes/splint.c
Normal file
20
lib/nr/ansi/recipes/splint.c
Normal file
@@ -0,0 +1,20 @@
|
||||
|
||||
void splint(float xa[], float ya[], float y2a[], int n, float x, float *y)
|
||||
{
|
||||
void nrerror(char error_text[]);
|
||||
int klo,khi,k;
|
||||
float h,b,a;
|
||||
|
||||
klo=1;
|
||||
khi=n;
|
||||
while (khi-klo > 1) {
|
||||
k=(khi+klo) >> 1;
|
||||
if (xa[k] > x) khi=k;
|
||||
else klo=k;
|
||||
}
|
||||
h=xa[khi]-xa[klo];
|
||||
if (h == 0.0) nrerror("Bad xa input to routine splint");
|
||||
a=(xa[khi]-x)/h;
|
||||
b=(x-xa[klo])/h;
|
||||
*y=a*ya[klo]+b*ya[khi]+((a*a*a-a)*y2a[klo]+(b*b*b-b)*y2a[khi])*(h*h)/6.0;
|
||||
}
|
||||
Reference in New Issue
Block a user