56void NaturalSpline (
int N,
const double* x,
const double* a, std::unique_ptr<
double[]>& b, std::unique_ptr<
double[]>& c,
57 std::unique_ptr<
double[]>& d)
59 const double oneThird = 1.0/3.0;
62 std::unique_ptr<double[]>
h(
new double[
N]);
63 std::unique_ptr<double[]> hdiff(
new double[
N]);
64 std::unique_ptr<double[]>
alpha(
new double[
N]);
66 for (
i = 0;
i <
N;
i++){
70 for (
i = 1;
i <
N;
i++)
71 hdiff[
i] =
x[
i+1]-
x[
i-1];
73 for (
i = 1;
i <
N;
i++)
75 double numer = 3.0*(
a[
i+1]*
h[
i-1]-
a[
i]*hdiff[
i]+
a[
i-1]*
h[
i]);
76 double denom =
h[
i-1]*
h[
i];
80 std::unique_ptr<double[]> ell(
new double[
N+1]);
81 std::unique_ptr<double[]> mu(
new double[
N]);
82 std::unique_ptr<double[]>
z(
new double[
N+1]);
89 for (
i = 1;
i <
N;
i++)
91 ell[
i] = 2.0*hdiff[
i]-
h[
i-1]*mu[
i-1];
99 b.reset(
new double[
N]);
100 c.reset(
new double[
N+1]);
101 d.reset(
new double[
N]);
105 for (
i =
N-1;
i >= 0;
i--)
107 c[
i] =
z[
i]-mu[
i]*c[
i+1];
109 b[
i] = recip*(
a[
i+1]-
a[
i])-
h[
i]*(c[
i+1]+2.0*c[
i])*oneThird;
110 d[
i] = oneThird*recip*(c[
i+1]-c[
i]);
114void PeriodicSpline (
int N,
const double* x,
const double* a, std::unique_ptr<
double[]>& b, std::unique_ptr<
double[]>& c,
115 std::unique_ptr<
double[]>& d)
117 std::unique_ptr<double[]>
h(
new double[
N]);
119 for (
i = 0;
i <
N;
i++)
131 for (
i = 1;
i <=
N-1;
i++)
133 mat[
i][
i-1] =
h[
i-1];
134 mat[
i][
i ] = 2.0f*(
h[
i-1]+
h[
i]);
142 mat[
N][
N-1] =
h[
N-1];
143 mat[
N][0 ] = 2.0f*(
h[
N-1]+
h[0]);
145 c[
N] = 3.0f*((
a[1]-
a[0])/
h[0] - (
a[0]-
a[
N-1])/
h[
N-1]);
150 const double oneThird = 1.0/3.0;
151 b.reset(
new double[
N]);
152 d.reset(
new double[
N]);
153 for (
i = 0;
i <
N;
i++)
155 b[
i] = (
a[
i+1]-
a[
i])/
h[
i] - oneThird*(c[
i+1]+2.0f*c[
i])*
h[
i];
156 d[
i] = oneThird*(c[
i+1]-c[
i])/
h[
i];
static bool Solve(int N, std::unique_ptr< std::unique_ptr< double[]>[]> const &A, double *b)
static std::unique_ptr< double[]> NewVector(int N)
static std::unique_ptr< std::unique_ptr< double[]>[]> NewMatrix(int N)
void PeriodicSpline(int N, const double *x, const double *a, std::unique_ptr< double[]> &b, std::unique_ptr< double[]> &c, std::unique_ptr< double[]> &d)
void NaturalSpline(int N, const double *x, const double *a, std::unique_ptr< double[]> &b, std::unique_ptr< double[]> &c, std::unique_ptr< double[]> &d)
constexpr double alpha[nDetails]