Menu

#95 Math function for gamma function and factorial for real numbers

Next Release
wont-fix
nobody
None
5
2019-12-01
2015-05-23
No

I suggest an approximation function for the gamma function. This allows a definition for a function to approximate the factorial function for real numbers.

Suggested code:

\pgfmathdeclarefunction{gamma}{1}{%
  \pgfmathmultiply{#1}{#1}%
  \let\pgfmath@gamma@tmp\pgfmathresult
  % tmp = x^2
  \pgfmathdivide{0.000793650793651}\pgfmath@gamma@tmp % 1/1260
  % result = 1/(1260 x^2)
  \pgfmathsubtract\pgfmathresult{0.00277777777778}% 1/360
  % result = -1/360 + 1/(1260 x^2)
  \pgfmathdivide\pgfmathresult\pgfmath@gamma@tmp
  % result = -1/(360 x^2) + 1/(1260 x^4)
  \pgfmathadd\pgfmathresult{0.0833333333333}% 1/12
  % result = 1/12 - 1/(360 x^2) + 1/(1260 x^4)
  \pgfmathdivide\pgfmathresult{#1}%
  \let\pgfmath@gamma@sum\pgfmathresult
  % sum = 1/(12 x) - 1/(360 x^3) + 1/(1260 x^5)
  \pgfmathmultiply{#1}{0.159154943092}% 1/(2 pi)
  % result = x/(2 pi)
  \pgfmathln\pgfmathresult
  % result = ln(x/(2 pi))
  \pgfmathmultiply\pgfmathresult{.5}%
  % result = (1/2) ln(x/(2 pi))
  \pgfmathadd\pgfmathresult{#1}%
  \let\pgfmath@gamma@tmp\pgfmathresult
  % tmp = x + (1/2) ln(x/(2 pi))
  \pgfmathln{#1}%
  % result = ln(x)
  \pgfmathmultiply\pgfmathresult{#1}%
  % result = x ln(x)
  \pgfmathsubtract\pgfmathresult\pgfmath@gamma@tmp
  % result = x ln(x) - x - (1/2) ln(x/(2 pi))
  \pgfmathadd\pgfmathresult\pgfmath@gamma@sum
  % result = x ln(x) - x - (1/2) ln(x/(2 pi))
  %          + 1/(12 x) - 1/(360 x^3) + 1/(1260 x^5)
  %        = ln(Gamma(x))
  \pgfmathexp\pgfmathresult
  % result = Gamma(x)
}

\pgfmathdeclarefunction{factorialreal}{1}{%
  \pgfmathadd{#1}{1}%
  \pgfmathgamma\pgfmathresult
}

A use case can be found here: Plotting using \pgfmathdeclarefunction and the factorial operator in TikZ

Discussion

  • Stefan Pinnow

    Stefan Pinnow - 2019-12-01
    • status: open --> wont-fix
     
  • Stefan Pinnow

    Stefan Pinnow - 2019-12-01
     
MongoDB Logo MongoDB