本文整理汇总了C++中ArrayXd::segment方法的典型用法代码示例。如果您正苦于以下问题:C++ ArrayXd::segment方法的具体用法?C++ ArrayXd::segment怎么用?C++ ArrayXd::segment使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ArrayXd
的用法示例。
在下文中一共展示了ArrayXd::segment方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: cubicSplineInterpolation
ArrayXd Functions::cubicSplineInterpolation(RefArrayXd const observedAbscissa, RefArrayXd const observedOrdinate,
RefArrayXd const interpolatedAbscissaUntruncated)
{
// Number of data points
int size = observedAbscissa.size();
// Number of interpolation grid points.
int interpolatedSize = interpolatedAbscissaUntruncated.size();
// Since the formula requires at least 2 data points, check if array size is not below 2,
// if the interpolated grid has at least one point, and if input abscissa and ordinate
// have same number of elements.
assert(size >= 2);
assert(interpolatedSize >= 1);
assert(observedOrdinate.size() == size);
// Check if lower bound set by observed abscissa is respected by interpolated abscissa
assert(observedAbscissa(0) <= interpolatedAbscissaUntruncated(0));
// Compare upper bound of observed and interpolated abscissas and truncate the latter if it exceeds the observed upper limit
double largestObservedAbscissa = observedAbscissa(size-1);
double largestInterpolatedAbscissa = interpolatedAbscissaUntruncated(interpolatedSize-1);
ArrayXd interpolatedAbscissa;
if (largestObservedAbscissa < largestInterpolatedAbscissa)
{
// Since upper bound of observed abscissa is lower, and the routine is not doing any extrapolation, truncate the array of
// interpolated abscissa at this upper bound.
int extraSize = Functions::countArrayIndicesWithinBoundaries(interpolatedAbscissaUntruncated, largestObservedAbscissa, largestInterpolatedAbscissa);
interpolatedSize = interpolatedSize - extraSize;
interpolatedAbscissa = interpolatedAbscissaUntruncated.segment(0,interpolatedSize);
}
else
interpolatedAbscissa = interpolatedAbscissaUntruncated;
// Define some array differences
ArrayXd differenceOrdinate = observedOrdinate.segment(1,size-1) - observedOrdinate.segment(0,size-1);
ArrayXd differenceAbscissa = observedAbscissa.segment(1,size-1) - observedAbscissa.segment(0,size-1);
ArrayXd differenceAbscissa2 = observedAbscissa.segment(2,size-2) - observedAbscissa.segment(0,size-2);
// Lower bound condition for natural spline
vector<double> secondDerivatives(size);
vector<double> partialSolution(size-1);
secondDerivatives[0] = 0.0;
partialSolution[0] = 0.0;
// Do tridiagonal decomposition for computing second derivatives of observed ordinate
ArrayXd sigma = differenceAbscissa.segment(0,size-2)/differenceAbscissa2.segment(0,size-2);
double beta;
// Forward computation of partial solutions in tridiagonal system
for (int i = 1; i < size-1; ++i)
{
beta = sigma(i-1) * secondDerivatives[i-1] + 2.0;
secondDerivatives[i] = (sigma(i-1) - 1.0)/beta;
partialSolution[i] = differenceOrdinate(i)/differenceAbscissa(i) - differenceOrdinate(i-1)/differenceAbscissa(i-1);
partialSolution[i] = (6.0*partialSolution[i]/differenceAbscissa2(i-1)-sigma(i-1)*partialSolution[i-1])/beta;
}
// Upper bound condition for natural spline
secondDerivatives[size-1] = 0.0;
// Backward substitution
for (int k = (size-2); k >= 0; --k)
{
secondDerivatives[k] = secondDerivatives[k]*secondDerivatives[k+1]+partialSolution[k];
}
// Initialize arrays of differences in both ordinate and abscissa
ArrayXd interpolatedOrdinate = ArrayXd::Zero(interpolatedSize);
ArrayXd remainingInterpolatedAbscissa = interpolatedAbscissa; // The remaining part of the array of interpolated abscissa
int cumulatedBinSize = 0; // The cumulated number of interpolated points from the beginning
int i = 0; // Bin counter
while ((i < size-1) && (cumulatedBinSize < interpolatedSize))
{
//.........这里部分代码省略.........