Skip to content
Snippets Groups Projects
Commit 3ac0b8e2 authored by Yonghui56's avatar Yonghui56
Browse files

fix typo

parent b0833038
No related branches found
No related tags found
No related merge requests found
......@@ -68,7 +68,7 @@ double PiecewiseLinearInterpolation::getValue(double pnt_to_interpolate) const
_values_at_supp_pnts[interval_idx];
}
double PiecewiseLinearInterpolation::GetDerivative(
double PiecewiseLinearInterpolation::getDerivative(
double const pnt_to_interpolate) const
{
if (pnt_to_interpolate < _supp_pnts.front() ||
......@@ -84,18 +84,18 @@ double PiecewiseLinearInterpolation::GetDerivative(
// interval_idx = interval_max - 1 - interval_idx;
if (interval_idx > 1 && interval_idx < _supp_pnts.size() - 2)
{
double const slope_right =
double const tangent_right =
(_values_at_supp_pnts[interval_idx] -
_values_at_supp_pnts[interval_idx + 2]) /
(_supp_pnts[interval_idx] - _supp_pnts[interval_idx + 2]);
double const slope_left =
double const tangent_left =
(_values_at_supp_pnts[interval_idx - 1] -
_values_at_supp_pnts[interval_idx + 1]) /
(_supp_pnts[interval_idx - 1] - _supp_pnts[interval_idx + 1]);
double const w =
(pnt_to_interpolate - _supp_pnts[interval_idx + 1]) /
(_supp_pnts[interval_idx] - _supp_pnts[interval_idx + 1]);
return (1. - w) * slope_right + w * slope_left;
return (1. - w) * tangent_right + w * tangent_left;
}
else
{
......
......@@ -70,13 +70,13 @@ public:
* \f$x_{\max} = \max_{1 \le j \le n} x_j\f$. when points are located
* outside of this interval
* the derivative is set to 0
* \attention if the points is located between the first and second points
* \attention if the points are located between the first and second points
* (or last and second to last point), the derivative is calculated by
* simple linear interpolation
* otherwise, it is calculated by second order of interpolation with central
* difference
*/
double GetDerivative(double pnt_to_interpolate) const;
double getDerivative(double const pnt_to_interpolate) const;
private:
std::vector<double> _supp_pnts;
......
......@@ -139,14 +139,14 @@ TEST(MathLibInterpolationAlgorithms, PiecewiseLinearInterpolationDerivative)
// Interpolation
for (std::size_t k(0); k < size - 1; ++k)
{
ASSERT_NEAR(1 + 2 * k, interpolation.GetDerivative(k + 0.5),
ASSERT_NEAR(1 + 2 * k, interpolation.getDerivative(k + 0.5),
std::numeric_limits<double>::epsilon());
}
// Extrapolation
ASSERT_NEAR(0, interpolation.GetDerivative(-1),
ASSERT_NEAR(0, interpolation.getDerivative(-1),
std::numeric_limits<double>::epsilon());
// Extrapolation
ASSERT_NEAR(0, interpolation.GetDerivative(1001),
ASSERT_NEAR(0, interpolation.getDerivative(1001),
std::numeric_limits<double>::epsilon());
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment