```Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!a7g2000yqb.googlegroups.com!not-for-mail
From: DOD <dcodea@gmail.com>
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
NNTP-Posting-Host: 128.174.250.146
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
X-Trace: posting.google.com 1316619719 16560 127.0.0.1 (21 Sep 2011 15:41:59 GMT)
NNTP-Posting-Date: Wed, 21 Sep 2011 15:41:59 +0000 (UTC)
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Windows NT 5.1; rv:6.0.2) Gecko/20100101 Firefox/6.0.2,gzip(gfe)
Xref: news.mathworks.com 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'))) ;

end

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?

Dennis
```