Evaluates the Angle distribution PDF.

You're viewing an older version of this page (#455). View the current version.

View versions (2)

Interface

#include <codecogs/statistics/distributions/continuous/angle/pdf.h>

using namespace Statistics::Distributions::Continuous::Angle;

Overview

This component evaluates the PDF of the Angle distribution with given arguments. x is an angle between 0 and \pi, corresponding to the angle made in an n dimensional space, between a fixed line passing through the origin, and an arbitrary line that also passes through the origin, which is specified by choosing any point on the n dimensional sphere with uniform probability.

The Angle PDF is defined by the following formula

\mathrm{P}(x) = \frac{ \sin^{n-2}(x)\,\Gamma\left(\frac{n}{2}\right) }
                     { \sqrt{\pi}\,\Gamma\left(\frac{n-1}{2}\right) }
\qquad \mbox{if } n > 2
(1)

and

\mathrm{P}(x) = \frac{1}{\pi} \qquad \mbox{if }n = 2
(2)

for all

x \in [0, \pi]
(3)

The mean of this distribution is given by

\mu = \frac{\pi}{2} \qquad \forall n, \mbox{ the spatial dimension}
(4)

In the example that follows, the PDF is evaluated using a fixed value for n, equal to 3, while the first argument x takes values from 0 up to 2 with a step equal to 0.2. The mean of the distribution, stored as a constant inside the same namespace, is also displayed. The maximum number of precision digits, implicitly set to 17, may be changed through the PRECISION define.

\graph x=0:3 n=3

Example 1

#include <codecogs/statistics/distributions/continuous/angle/pdf.h>
#include <iostream>
#include <iomanip>

#define PRECISION 17

int main()
{
  std::cout << "The values of the Angle PDF with n = 3 and";
  std::cout << std::endl;
  std::cout << "x = {0, 0.2, 0.4, ..., 1.8, 2} are" << std::endl;
  std::cout << std::endl;
  for (double x = 0; x < 2.1; x += 0.2)
  {
    std::cout << std::setprecision(2);
    std::cout << "x = " << std::setw(3) << x << " : ";
    std::cout << std::setprecision(PRECISION);
    std::cout << Stats::Dists::Continuous::Angle::PDF(x, 3);
    std::cout << std::endl;
  }
  std::cout << std::endl;
  std::cout << "The mean of the Angle distribution is equal to";
  std::cout << std::endl;
  std::cout << Stats::Dists::Continuous::Angle::mean;
  std::cout << std::endl;
  return 0;
}

Output:

The values of the Angle PDF with n = 3 and
x = {0, 0.2, 0.4, ..., 1.8, 2} are

x = 0 : 0
x = 0.2 : 0.099334665397530608
x = 0.4 : 0.19470917115432523
x = 0.6 : 0.28232123669751769
x = 0.8 : 0.35867804544976134
x = 1 : 0.4207354924039482
x = 1.2 : 0.46601954298361309
x = 1.4 : 0.49272486499422996
x = 1.6 : 0.49978680152075255
x = 1.8 : 0.48692381543909757
x = 2 : 0.45464871341284085

The mean of the Angle distribution is equal to
1.5707963267948966

Parameters

x
the argument of the PDF
n
the spatial dimension (must be at least 2)

Returns

the value of the Angle PDF evaluated with the given arguments

References

John Burkardt's library of statistical C++ routines, http://www.csit.fsu.edu/~burkardt/cpp_src/prob/prob.html

GPL Licence — free for non commercial use. See Licence details.

DECLARATION

mean