From: DOD <>
Newsgroups: comp.soft-sys.matlab
Subject: Innaccuracy in a gammainc and , how best to override?
Date: Wed, 21 Sep 2011 08:40:11 -0700 (PDT)
Lines: 27
Message-ID: <>
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
X-Trace: 1316619719 16560 (21 Sep 2011 15:41:59 GMT)
NNTP-Posting-Date: Wed, 21 Sep 2011 15:41:59 +0000 (UTC)
Injection-Info:; posting-host=; posting-account=yN5uLwoAAAD-9ZO1c3IjHfbc8c1Nakp-
User-Agent: G2/1.0
X-Google-Web-Client: true
X-Google-Header-Order: HUALESNKC
X-HTTP-UserAgent: Mozilla/5.0 (Windows NT 5.1; rv:6.0.2) Gecko/20100101 Firefox/6.0.2,gzip(gfe)
Xref: comp.soft-sys.matlab:743792

Here is a function

function out = exact_d_cgf(t,lambda,delta)
A = - lambda ./ log(delta);

out = real( (-A ./ t)  - (exp(t) .* (-t) .^ (A-1) ) ./
( gamma(A)*gammainc(-t,A,'lower'))) ;


I know, for theoretical reasons, that lim t->inf,  exact_d_cgf -> 1.
However, for t>~ 30, there is inaccuracy in this calculation; I
imagine it has to do with gammainc(-t,A,'lower') ->inf and (-A ./ t)
- (exp(t) .* (-t) .^ (A-1) )  ->inf at the same time with t.

For large t, this begins to fluctuate and introduces errors.  What is
the best way to override this?  I tried somethings like

out = min([ real(...) 1])

but the problem is the innaccuracy goes either way; sometimes it
returns arbirarilty large answers, and sometimes it returns small
answers.    What is my best bet?  Just force out = 1 for t>tbar, where
I just pick tbar by hand?