diff options
Diffstat (limited to 'boost/math/distributions/triangular.hpp')
-rw-r--r-- | boost/math/distributions/triangular.hpp | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/boost/math/distributions/triangular.hpp b/boost/math/distributions/triangular.hpp index 78ef0df744..1e49a38faf 100644 --- a/boost/math/distributions/triangular.hpp +++ b/boost/math/distributions/triangular.hpp @@ -8,6 +8,12 @@ #define BOOST_STATS_TRIANGULAR_HPP // http://mathworld.wolfram.com/TriangularDistribution.html +// Note that the 'constructors' defined by Wolfram are difference from those here, +// for example +// N[variance[triangulardistribution{1, +2}, 1.5], 50] computes +// 0.041666666666666666666666666666666666666666666666667 +// TriangularDistribution{1, +2}, 1.5 is the analog of triangular_distribution(1, 1.5, 2) + // http://en.wikipedia.org/wiki/Triangular_distribution #include <boost/math/distributions/fwd.hpp> @@ -449,7 +455,7 @@ namespace boost{ namespace math } RealType lower = dist.lower(); RealType upper = dist.upper(); - if (mode < (upper - lower) / 2) + if (mode >= (upper + lower) / 2) { return lower + sqrt((upper - lower) * (mode - lower)) / constants::root_two<RealType>(); } @@ -475,7 +481,9 @@ namespace boost{ namespace math return result; } return root_two<RealType>() * (lower + upper - 2 * mode) * (2 * lower - upper - mode) * (lower - 2 * upper + mode) / - (5 * pow((lower * lower + upper + upper + mode * mode - lower * upper - lower * mode - upper * mode), RealType(3)/RealType(2))); + (5 * pow((lower * lower + upper * upper + mode * mode + - lower * upper - lower * mode - upper * mode), RealType(3)/RealType(2))); + // #11768: Skewness formula for triangular distribution is incorrect - corrected 29 Oct 2015 for release 1.61. } // RealType skewness(const triangular_distribution<RealType, Policy>& dist) template <class RealType, class Policy> |