Files
2025-02-Numerical/lib/nr/cpp/recipes/splint.cpp
2025-09-12 18:55:25 +09:00

23 lines
438 B
C++

#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;
}