Approximating the Digamma function

Clash Royale CLAN TAG#URR8PPP
up vote
3
down vote
favorite
I am trying to approximate the digamma function in order to graph it in latex. I've already found an approximation of the gamma function from the Tex SE:
$$
Gamma(z)=
(2.506628274631sqrt(1/z) + 0.20888568(1/z)^(1.5) + 0.00870357(1/z)^(2.5) - frac(174.2106599*(1/z)^(3.5))25920 - frac(715.6423511(1/z)^(4.5))1244160)exp((-ln(1/z)-1)z)
$$
and for the digamma, $psi$, ive been using an approximation of the derivative:
$$
psi(x)=fracln Gamma(x+0.0001)-ln Gamma(x-0.0001)0.0002
$$
But im wondering if there is a better way
numerical-methods gamma-function digamma-function
add a comment |Â
up vote
3
down vote
favorite
I am trying to approximate the digamma function in order to graph it in latex. I've already found an approximation of the gamma function from the Tex SE:
$$
Gamma(z)=
(2.506628274631sqrt(1/z) + 0.20888568(1/z)^(1.5) + 0.00870357(1/z)^(2.5) - frac(174.2106599*(1/z)^(3.5))25920 - frac(715.6423511(1/z)^(4.5))1244160)exp((-ln(1/z)-1)z)
$$
and for the digamma, $psi$, ive been using an approximation of the derivative:
$$
psi(x)=fracln Gamma(x+0.0001)-ln Gamma(x-0.0001)0.0002
$$
But im wondering if there is a better way
numerical-methods gamma-function digamma-function
add a comment |Â
up vote
3
down vote
favorite
up vote
3
down vote
favorite
I am trying to approximate the digamma function in order to graph it in latex. I've already found an approximation of the gamma function from the Tex SE:
$$
Gamma(z)=
(2.506628274631sqrt(1/z) + 0.20888568(1/z)^(1.5) + 0.00870357(1/z)^(2.5) - frac(174.2106599*(1/z)^(3.5))25920 - frac(715.6423511(1/z)^(4.5))1244160)exp((-ln(1/z)-1)z)
$$
and for the digamma, $psi$, ive been using an approximation of the derivative:
$$
psi(x)=fracln Gamma(x+0.0001)-ln Gamma(x-0.0001)0.0002
$$
But im wondering if there is a better way
numerical-methods gamma-function digamma-function
I am trying to approximate the digamma function in order to graph it in latex. I've already found an approximation of the gamma function from the Tex SE:
$$
Gamma(z)=
(2.506628274631sqrt(1/z) + 0.20888568(1/z)^(1.5) + 0.00870357(1/z)^(2.5) - frac(174.2106599*(1/z)^(3.5))25920 - frac(715.6423511(1/z)^(4.5))1244160)exp((-ln(1/z)-1)z)
$$
and for the digamma, $psi$, ive been using an approximation of the derivative:
$$
psi(x)=fracln Gamma(x+0.0001)-ln Gamma(x-0.0001)0.0002
$$
But im wondering if there is a better way
numerical-methods gamma-function digamma-function
asked Sep 19 '15 at 4:00
dimebucker
1,516921
1,516921
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
4
down vote
accepted
Yes, there is a formula
$$ÃÂ(x) approx log(x) + frac12x - frac112x^2 +frac1120x^4 -frac1252x^6 +frac1240x^8 -frac5660x^10+frac69132760x^12 -frac112x^14$$
This is especially accurate for larger values of $x$. If $x$ is small, you can shift $x$ to a higher value using the relation
$$ÃÂ(x+1) = frac1x ÃÂ(x)$$
You can find my source here, under "Computation and Approximation".
Edit: Accuracy of Approximation
This series is quite accurate for $x$ in the interval $(1,infty)$. Given the OP's bounds of $x = (0,20)$, we can find the difference between the expected and calculated results (note that $S(x)$ is the series in question)
$$ÃÂ(1) - S(1) = 0.0674022$$
$$ÃÂ(20) - S(20) = 4.44089ÃÂ10^-16$$
From these results we find that we get exactly what we expected: the series is decent in this interval, but is MUCH better for larger $x$. However, we get a problem for $x = frac12$:
$$ÃÂ(frac12) - S(frac12) = 1285.81$$
Obviously we are way off here. However, some context is useful. Our series blows up for $x<1$ towards $-infty$, and so we can't expect anything useful here. Nevertheless, we can use the shift formula above to mitigate this issue, rewriting it as
$$ÃÂ(x) = xÃÂ(x+1)$$
Applying this just once for $x=frac12$, we get a difference of $1.9816604...$, an approximation $approx 650$ times better. Thus, we see that we can use the series provided to get a decent approximation of the graph of $ÃÂ(x)$ for all $x>0$.
ahh, should've checked the wiki, thanks!
â dimebucker
Sep 19 '15 at 4:22
@dimebucker91 Sure thing! Note that this is an asymptotic series, hence why it works better for larger $x$ (and gets better and better as $x to infty$). I'm sure you can find series that are derived from other methods that will work for smaller values of $x$ with a little searching (if that is what you need)... it all depends on the domain you are graphing in
â Brevan Ellefsen
Sep 19 '15 at 4:24
I was hoping to use it for $0<x le 20$
â dimebucker
Sep 19 '15 at 4:25
1
I'll check the bounds on the series and give you a worst case scenario on the difference between this series and the actual values... give me a minute.
â Brevan Ellefsen
Sep 19 '15 at 4:26
1
@dimebucker91 I did the calculations and provided my results in an edit to my post (tripling my post length). I hope this is helpful to you!
â Brevan Ellefsen
Sep 19 '15 at 4:50
 |Â
show 3 more comments
up vote
3
down vote
Since you need an implementation for graphing, a simple approximation with relative low accuracy and optimized for absolute error seems suitable. A short search with computer program shows that $$psi(x) approx ln (x + a) - frac1b x, space a = 0.4849142940227510, space b=1.0271785180163817$$
approximates with an absolute error of less than $0.00123$ on $[frac12, 2^1024)$ when evaluated in IEEE-754 double precision. For arguments $x lt frac12$, the function can be computed using the reflection formula $psi(x) = psi(1-x) + pi space cot space(pi (1-x))$.
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
accepted
Yes, there is a formula
$$ÃÂ(x) approx log(x) + frac12x - frac112x^2 +frac1120x^4 -frac1252x^6 +frac1240x^8 -frac5660x^10+frac69132760x^12 -frac112x^14$$
This is especially accurate for larger values of $x$. If $x$ is small, you can shift $x$ to a higher value using the relation
$$ÃÂ(x+1) = frac1x ÃÂ(x)$$
You can find my source here, under "Computation and Approximation".
Edit: Accuracy of Approximation
This series is quite accurate for $x$ in the interval $(1,infty)$. Given the OP's bounds of $x = (0,20)$, we can find the difference between the expected and calculated results (note that $S(x)$ is the series in question)
$$ÃÂ(1) - S(1) = 0.0674022$$
$$ÃÂ(20) - S(20) = 4.44089ÃÂ10^-16$$
From these results we find that we get exactly what we expected: the series is decent in this interval, but is MUCH better for larger $x$. However, we get a problem for $x = frac12$:
$$ÃÂ(frac12) - S(frac12) = 1285.81$$
Obviously we are way off here. However, some context is useful. Our series blows up for $x<1$ towards $-infty$, and so we can't expect anything useful here. Nevertheless, we can use the shift formula above to mitigate this issue, rewriting it as
$$ÃÂ(x) = xÃÂ(x+1)$$
Applying this just once for $x=frac12$, we get a difference of $1.9816604...$, an approximation $approx 650$ times better. Thus, we see that we can use the series provided to get a decent approximation of the graph of $ÃÂ(x)$ for all $x>0$.
ahh, should've checked the wiki, thanks!
â dimebucker
Sep 19 '15 at 4:22
@dimebucker91 Sure thing! Note that this is an asymptotic series, hence why it works better for larger $x$ (and gets better and better as $x to infty$). I'm sure you can find series that are derived from other methods that will work for smaller values of $x$ with a little searching (if that is what you need)... it all depends on the domain you are graphing in
â Brevan Ellefsen
Sep 19 '15 at 4:24
I was hoping to use it for $0<x le 20$
â dimebucker
Sep 19 '15 at 4:25
1
I'll check the bounds on the series and give you a worst case scenario on the difference between this series and the actual values... give me a minute.
â Brevan Ellefsen
Sep 19 '15 at 4:26
1
@dimebucker91 I did the calculations and provided my results in an edit to my post (tripling my post length). I hope this is helpful to you!
â Brevan Ellefsen
Sep 19 '15 at 4:50
 |Â
show 3 more comments
up vote
4
down vote
accepted
Yes, there is a formula
$$ÃÂ(x) approx log(x) + frac12x - frac112x^2 +frac1120x^4 -frac1252x^6 +frac1240x^8 -frac5660x^10+frac69132760x^12 -frac112x^14$$
This is especially accurate for larger values of $x$. If $x$ is small, you can shift $x$ to a higher value using the relation
$$ÃÂ(x+1) = frac1x ÃÂ(x)$$
You can find my source here, under "Computation and Approximation".
Edit: Accuracy of Approximation
This series is quite accurate for $x$ in the interval $(1,infty)$. Given the OP's bounds of $x = (0,20)$, we can find the difference between the expected and calculated results (note that $S(x)$ is the series in question)
$$ÃÂ(1) - S(1) = 0.0674022$$
$$ÃÂ(20) - S(20) = 4.44089ÃÂ10^-16$$
From these results we find that we get exactly what we expected: the series is decent in this interval, but is MUCH better for larger $x$. However, we get a problem for $x = frac12$:
$$ÃÂ(frac12) - S(frac12) = 1285.81$$
Obviously we are way off here. However, some context is useful. Our series blows up for $x<1$ towards $-infty$, and so we can't expect anything useful here. Nevertheless, we can use the shift formula above to mitigate this issue, rewriting it as
$$ÃÂ(x) = xÃÂ(x+1)$$
Applying this just once for $x=frac12$, we get a difference of $1.9816604...$, an approximation $approx 650$ times better. Thus, we see that we can use the series provided to get a decent approximation of the graph of $ÃÂ(x)$ for all $x>0$.
ahh, should've checked the wiki, thanks!
â dimebucker
Sep 19 '15 at 4:22
@dimebucker91 Sure thing! Note that this is an asymptotic series, hence why it works better for larger $x$ (and gets better and better as $x to infty$). I'm sure you can find series that are derived from other methods that will work for smaller values of $x$ with a little searching (if that is what you need)... it all depends on the domain you are graphing in
â Brevan Ellefsen
Sep 19 '15 at 4:24
I was hoping to use it for $0<x le 20$
â dimebucker
Sep 19 '15 at 4:25
1
I'll check the bounds on the series and give you a worst case scenario on the difference between this series and the actual values... give me a minute.
â Brevan Ellefsen
Sep 19 '15 at 4:26
1
@dimebucker91 I did the calculations and provided my results in an edit to my post (tripling my post length). I hope this is helpful to you!
â Brevan Ellefsen
Sep 19 '15 at 4:50
 |Â
show 3 more comments
up vote
4
down vote
accepted
up vote
4
down vote
accepted
Yes, there is a formula
$$ÃÂ(x) approx log(x) + frac12x - frac112x^2 +frac1120x^4 -frac1252x^6 +frac1240x^8 -frac5660x^10+frac69132760x^12 -frac112x^14$$
This is especially accurate for larger values of $x$. If $x$ is small, you can shift $x$ to a higher value using the relation
$$ÃÂ(x+1) = frac1x ÃÂ(x)$$
You can find my source here, under "Computation and Approximation".
Edit: Accuracy of Approximation
This series is quite accurate for $x$ in the interval $(1,infty)$. Given the OP's bounds of $x = (0,20)$, we can find the difference between the expected and calculated results (note that $S(x)$ is the series in question)
$$ÃÂ(1) - S(1) = 0.0674022$$
$$ÃÂ(20) - S(20) = 4.44089ÃÂ10^-16$$
From these results we find that we get exactly what we expected: the series is decent in this interval, but is MUCH better for larger $x$. However, we get a problem for $x = frac12$:
$$ÃÂ(frac12) - S(frac12) = 1285.81$$
Obviously we are way off here. However, some context is useful. Our series blows up for $x<1$ towards $-infty$, and so we can't expect anything useful here. Nevertheless, we can use the shift formula above to mitigate this issue, rewriting it as
$$ÃÂ(x) = xÃÂ(x+1)$$
Applying this just once for $x=frac12$, we get a difference of $1.9816604...$, an approximation $approx 650$ times better. Thus, we see that we can use the series provided to get a decent approximation of the graph of $ÃÂ(x)$ for all $x>0$.
Yes, there is a formula
$$ÃÂ(x) approx log(x) + frac12x - frac112x^2 +frac1120x^4 -frac1252x^6 +frac1240x^8 -frac5660x^10+frac69132760x^12 -frac112x^14$$
This is especially accurate for larger values of $x$. If $x$ is small, you can shift $x$ to a higher value using the relation
$$ÃÂ(x+1) = frac1x ÃÂ(x)$$
You can find my source here, under "Computation and Approximation".
Edit: Accuracy of Approximation
This series is quite accurate for $x$ in the interval $(1,infty)$. Given the OP's bounds of $x = (0,20)$, we can find the difference between the expected and calculated results (note that $S(x)$ is the series in question)
$$ÃÂ(1) - S(1) = 0.0674022$$
$$ÃÂ(20) - S(20) = 4.44089ÃÂ10^-16$$
From these results we find that we get exactly what we expected: the series is decent in this interval, but is MUCH better for larger $x$. However, we get a problem for $x = frac12$:
$$ÃÂ(frac12) - S(frac12) = 1285.81$$
Obviously we are way off here. However, some context is useful. Our series blows up for $x<1$ towards $-infty$, and so we can't expect anything useful here. Nevertheless, we can use the shift formula above to mitigate this issue, rewriting it as
$$ÃÂ(x) = xÃÂ(x+1)$$
Applying this just once for $x=frac12$, we get a difference of $1.9816604...$, an approximation $approx 650$ times better. Thus, we see that we can use the series provided to get a decent approximation of the graph of $ÃÂ(x)$ for all $x>0$.
edited Aug 25 at 5:58
answered Sep 19 '15 at 4:16
Brevan Ellefsen
11.4k31449
11.4k31449
ahh, should've checked the wiki, thanks!
â dimebucker
Sep 19 '15 at 4:22
@dimebucker91 Sure thing! Note that this is an asymptotic series, hence why it works better for larger $x$ (and gets better and better as $x to infty$). I'm sure you can find series that are derived from other methods that will work for smaller values of $x$ with a little searching (if that is what you need)... it all depends on the domain you are graphing in
â Brevan Ellefsen
Sep 19 '15 at 4:24
I was hoping to use it for $0<x le 20$
â dimebucker
Sep 19 '15 at 4:25
1
I'll check the bounds on the series and give you a worst case scenario on the difference between this series and the actual values... give me a minute.
â Brevan Ellefsen
Sep 19 '15 at 4:26
1
@dimebucker91 I did the calculations and provided my results in an edit to my post (tripling my post length). I hope this is helpful to you!
â Brevan Ellefsen
Sep 19 '15 at 4:50
 |Â
show 3 more comments
ahh, should've checked the wiki, thanks!
â dimebucker
Sep 19 '15 at 4:22
@dimebucker91 Sure thing! Note that this is an asymptotic series, hence why it works better for larger $x$ (and gets better and better as $x to infty$). I'm sure you can find series that are derived from other methods that will work for smaller values of $x$ with a little searching (if that is what you need)... it all depends on the domain you are graphing in
â Brevan Ellefsen
Sep 19 '15 at 4:24
I was hoping to use it for $0<x le 20$
â dimebucker
Sep 19 '15 at 4:25
1
I'll check the bounds on the series and give you a worst case scenario on the difference between this series and the actual values... give me a minute.
â Brevan Ellefsen
Sep 19 '15 at 4:26
1
@dimebucker91 I did the calculations and provided my results in an edit to my post (tripling my post length). I hope this is helpful to you!
â Brevan Ellefsen
Sep 19 '15 at 4:50
ahh, should've checked the wiki, thanks!
â dimebucker
Sep 19 '15 at 4:22
ahh, should've checked the wiki, thanks!
â dimebucker
Sep 19 '15 at 4:22
@dimebucker91 Sure thing! Note that this is an asymptotic series, hence why it works better for larger $x$ (and gets better and better as $x to infty$). I'm sure you can find series that are derived from other methods that will work for smaller values of $x$ with a little searching (if that is what you need)... it all depends on the domain you are graphing in
â Brevan Ellefsen
Sep 19 '15 at 4:24
@dimebucker91 Sure thing! Note that this is an asymptotic series, hence why it works better for larger $x$ (and gets better and better as $x to infty$). I'm sure you can find series that are derived from other methods that will work for smaller values of $x$ with a little searching (if that is what you need)... it all depends on the domain you are graphing in
â Brevan Ellefsen
Sep 19 '15 at 4:24
I was hoping to use it for $0<x le 20$
â dimebucker
Sep 19 '15 at 4:25
I was hoping to use it for $0<x le 20$
â dimebucker
Sep 19 '15 at 4:25
1
1
I'll check the bounds on the series and give you a worst case scenario on the difference between this series and the actual values... give me a minute.
â Brevan Ellefsen
Sep 19 '15 at 4:26
I'll check the bounds on the series and give you a worst case scenario on the difference between this series and the actual values... give me a minute.
â Brevan Ellefsen
Sep 19 '15 at 4:26
1
1
@dimebucker91 I did the calculations and provided my results in an edit to my post (tripling my post length). I hope this is helpful to you!
â Brevan Ellefsen
Sep 19 '15 at 4:50
@dimebucker91 I did the calculations and provided my results in an edit to my post (tripling my post length). I hope this is helpful to you!
â Brevan Ellefsen
Sep 19 '15 at 4:50
 |Â
show 3 more comments
up vote
3
down vote
Since you need an implementation for graphing, a simple approximation with relative low accuracy and optimized for absolute error seems suitable. A short search with computer program shows that $$psi(x) approx ln (x + a) - frac1b x, space a = 0.4849142940227510, space b=1.0271785180163817$$
approximates with an absolute error of less than $0.00123$ on $[frac12, 2^1024)$ when evaluated in IEEE-754 double precision. For arguments $x lt frac12$, the function can be computed using the reflection formula $psi(x) = psi(1-x) + pi space cot space(pi (1-x))$.
add a comment |Â
up vote
3
down vote
Since you need an implementation for graphing, a simple approximation with relative low accuracy and optimized for absolute error seems suitable. A short search with computer program shows that $$psi(x) approx ln (x + a) - frac1b x, space a = 0.4849142940227510, space b=1.0271785180163817$$
approximates with an absolute error of less than $0.00123$ on $[frac12, 2^1024)$ when evaluated in IEEE-754 double precision. For arguments $x lt frac12$, the function can be computed using the reflection formula $psi(x) = psi(1-x) + pi space cot space(pi (1-x))$.
add a comment |Â
up vote
3
down vote
up vote
3
down vote
Since you need an implementation for graphing, a simple approximation with relative low accuracy and optimized for absolute error seems suitable. A short search with computer program shows that $$psi(x) approx ln (x + a) - frac1b x, space a = 0.4849142940227510, space b=1.0271785180163817$$
approximates with an absolute error of less than $0.00123$ on $[frac12, 2^1024)$ when evaluated in IEEE-754 double precision. For arguments $x lt frac12$, the function can be computed using the reflection formula $psi(x) = psi(1-x) + pi space cot space(pi (1-x))$.
Since you need an implementation for graphing, a simple approximation with relative low accuracy and optimized for absolute error seems suitable. A short search with computer program shows that $$psi(x) approx ln (x + a) - frac1b x, space a = 0.4849142940227510, space b=1.0271785180163817$$
approximates with an absolute error of less than $0.00123$ on $[frac12, 2^1024)$ when evaluated in IEEE-754 double precision. For arguments $x lt frac12$, the function can be computed using the reflection formula $psi(x) = psi(1-x) + pi space cot space(pi (1-x))$.
answered Sep 22 '15 at 6:43
njuffa
6761813
6761813
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f1441753%2fapproximating-the-digamma-function%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password