add numerical recipes library
This commit is contained in:
22
lib/nr/cpp/recipes/splint.cpp
Normal file
22
lib/nr/cpp/recipes/splint.cpp
Normal file
@@ -0,0 +1,22 @@
|
||||
#include "nr.h"
|
||||
|
||||
void NR::splint(Vec_I_DP &xa, Vec_I_DP &ya, Vec_I_DP &y2a, const DP x, DP &y)
|
||||
{
|
||||
int k;
|
||||
DP h,b,a;
|
||||
|
||||
int n=xa.size();
|
||||
int klo=0;
|
||||
int khi=n-1;
|
||||
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