Login [Register]
Don't have an account? Register now to chat, post, use our tools, and much more.
This is an archived, read-only copy of the United-TI subforum , including posts and topic from May 2003 to April 2012. If you would like to discuss any of the topics in this forum, you can visit Cemetech's Technology & Calculator Open Topic subforum. Some of these topics may also be directly-linked to active Cemetech topics. If you are a Cemetech member with a linked United-TI account, you can link United-TI topics here with your current Cemetech topics.

This forum is locked: you cannot post, reply to, or edit topics. Math and Science => Technology & Calculator Open Topic
Author Message
Graphmastur


Advanced Member


Joined: 25 Mar 2009
Posts: 360

Posted: 27 Apr 2010 07:46:01 pm    Post subject:

Simply for the record. THIS IS NOT A HOMEWORK QUESTION. Okay, now on to the homework looking question...

Okay, I have this integral:
[attachment=3168:gamma(Z).tiff]
If I want to find the antiderivative (indefinite derivative?) of the function, how do I do it? This will allow me to solve it right? If not, how do I solve it quickly?

My overall goal is to solve it fairly quickly, or in a reasonable amount of time. Is this possible? I will be using a HUGE n value, I don't know what z is just yet, and t is the variable, so.... please help.

Also, ignore the "/; Re(z)>0" thing. I think that means it's just real numbers greater than 0, or something. Since I only want to use real positive numbers for z, that's no problem.

Also, I understand the derivative. Antiderivatives are still above my current level. So, how do I solve this?

Thanks in advance.
Back to top
wesley


Newbie


Joined: 05 May 2009
Posts: 45

Posted: 27 Apr 2010 08:29:06 pm    Post subject:

Well, that's pretty funny. That's no ordinary antiderivative you've got there. That is a gamma function. You learn about those in probability and statistics with applied calculus (calculus 2).

Also, yours has a limit. This is the most important thing. It doesn't mean you keep integrating for every value of n, that would take forever of course! (Considering the fact that n goes to infinite.) Thus, you simply substitute infinite with an arbitrary variable until you are done integrating, at which point, you will insert infinite for that variable you placed in the equation.

Also, the antiderivative is simply an integral, not an indefinite derivative.

This problem can be solved in a quick manner of time, but it takes some good thought and understanding the gamma function.

This is NOT, by any means an elementary calculus problem. If it isn't homework, do you mind sharing its source?

I didn't dive too deep into the gamma function in my class last year, but we went over it a little, so it is familiar.


Last edited by Guest on 27 Apr 2010 08:32:05 pm; edited 1 time in total
Back to top
Graphmastur


Advanced Member


Joined: 25 Mar 2009
Posts: 360

Posted: 27 Apr 2010 10:03:46 pm    Post subject:

Wesley wrote:

Also, yours has a limit. This is the most important thing. It doesn't mean you keep integrating for every value of n, that would take forever of course! (Considering the fact that n goes to infinite.) Thus, you simply substitute infinite with an arbitrary variable until you are done integrating, at which point, you will insert infinite for that variable you placed in the equation.

This problem can be solved in a quick manner of time, but it takes some good thought and understanding the gamma function.

This is NOT, by any means an elementary calculus problem. If it isn't homework, do you mind sharing its source?

So in order:
I will be using java, so I will substitute some HUGE number to use for infinity.

Yeah, I know limits and derivatives. I know antiderivatives of polynomial functions, but nothing else. I know nothing of solving them either.

The source of the function is wolfram. I'm trying to find a factorial fairly quickly, so I decided to use the gamma function. This works perfectly in mac grapher, but I don't know how to do integrals at all.

This is a programming question, because I need to be able to implement it. Thanks for the quick reply.
Back to top
wesley


Newbie


Joined: 05 May 2009
Posts: 45

Posted: 27 Apr 2010 10:38:25 pm    Post subject:

Oh, I see.

Why don't you just make an implementation with memorization. This would be a great deal better than recursion (as you most-likely know).
Back to top
wesley


Newbie


Joined: 05 May 2009
Posts: 45

Posted: 28 Apr 2010 12:25:22 am    Post subject:

Ah, man!

I can't believe I got hooked on this problem!

Just to calculate that integral, you need to take just as many steps as multiplying all the numbers from 1 to n. The integral is recursive, you need to use integration by parts.
Back to top
thornahawk
μολών λαβέ


Active Member


Joined: 27 Mar 2005
Posts: 569

Posted: 28 Apr 2010 04:45:21 am    Post subject:

It looks to me like a not-too-docile (for numerical work, that is) integral, not in any event any more advantageous than (for instance) the defining infinite integral for the gamma function.

"This is a programming question, because I need to be able to implement it."

There are so much better methods for calculating a gamma function; the Stirling and Lanczos approximations being the most popular. You should look into those instead of looking for integrals.

If my words are not convincing enough, you might wish to peruse the following Mathematica output:


The entries of that table are of the form -log10(|(f(n,z)-Γ(z))/Γ(z)|) (i.e. the negative common logarithm of the relative error), where n is the row heading, z is the column heading, and f(n,z) is the expression inside the limit. As you can see you only gain one digit of accuracy every time you increase n ten times. Much ado about nothing when there are ways to compute the gamma function more accurately with less effort.

thornahawk
Back to top
Graphmastur


Advanced Member


Joined: 25 Mar 2009
Posts: 360

Posted: 28 Apr 2010 06:39:51 am    Post subject:

thornahawk wrote:

It looks to me like a not-too-docile (for numerical work, that is) integral, not in any event any more advantageous than (for instance) the defining infinite integral for the gamma function.

"This is a programming question, because I need to be able to implement it."

There are so much better methods for calculating a gamma function; the Stirling and Lanczos approximations being the most popular. You should look into those instead of looking for integrals.

If my words are not convincing enough, you might wish to peruse the following Mathematica output:


The entries of that table are of the form -log10(|(f(n,z)-Γ(z))/Γ(z)|) (i.e. the negative common logarithm of the relative error), where n is the row heading, z is the column heading, and f(n,z) is the expression inside the limit. As you can see you only gain one digit of accuracy every time you increase n ten times. Much ado about nothing when there are ways to compute the gamma function more accurately with less effort.

thornahawk

The problem is that it needs to be accurate. Why can't I just solve the integral? N would be huge, so that shouldn't be a problem.
Back to top
thornahawk
μολών λαβέ


Active Member


Joined: 27 Mar 2005
Posts: 569

Posted: 28 Apr 2010 08:20:59 am    Post subject:

Hmm, I seem to have screwed the labeling up in that post; the rows are supposed to be the z values and the columns the n values for that integral. As you have seen it required a limit of 108 (and approximately the same amount of function evaluations) to get merely 8 digit accuracy. Stirling and Lanczos, written properly, can give 12-14 digit accuracy with less effort.

thornahawk
Back to top
Graphmastur


Advanced Member


Joined: 25 Mar 2009
Posts: 360

Posted: 28 Apr 2010 05:35:07 pm    Post subject:

thornahawk wrote:

Hmm, I seem to have screwed the labeling up in that post; the rows are supposed to be the z values and the columns the n values for that integral. As you have seen it required a limit of 108 (and approximately the same amount of function evaluations) to get merely 8 digit accuracy. Stirling and Lanczos, written properly, can give 12-14 digit accuracy with less effort.

thornahawk

So if I do a 1099999, it will give me 99999 digits accuracy? So even if the other two are better, how do I work this problem?
Back to top
thornahawk
μολών λαβέ


Active Member


Joined: 27 Mar 2005
Posts: 569

Posted: 28 Apr 2010 09:06:35 pm    Post subject:

If you truly insist on this route (which I still think is a profligate waste given that I have already mentioned better alternatives which you still choose to ignore), I shall give another piece of evidence that might force you to reconsider.

Your integrand (the expression inside your integral) is of the following form:

(1-t/n)ntz-1

where n will be a large number in your calculations (since you can't take limits on the computer anyway) and z is the argument of the gamma function. Any numerical integration algorithm, from the simplest trapezoidal to the most convoluted adaptive quadrature scheme, will involve evaluating your integrand for a large bunch of numbers within the open interval (0,n).

Since you say you will be using Java's floating-point machinery, I assume you are already aware of concepts like overflow/underflow and machine epsilon. To be specific, if t/n ever becomes less than machine epsilon, your integrand is effectively the same as tz-1. That impacts the accuracy of calculations in your left portion of the interval.

On the right portion of your interval (near n), you risk overflow/underflow in your computation. As an exercise, pick a large enough n and a fixed z, and try computing the integrand for values of t near 0 and near n. You'd be surprised.

As a final note, I wish to remind you that one way of reducing the burden of computing the gamma function is to reduce the argument to a preset unit interval, e.g. (0,1] or (1,2]; the functional equation for gamma takes care of arguments outside your preset interval.

thornahawk
Back to top
Graphmastur


Advanced Member


Joined: 25 Mar 2009
Posts: 360

Posted: 28 Apr 2010 09:37:57 pm    Post subject:

I will use one of the other methods, if they can give me completely accurate. Is this possible?
Back to top
wesley


Newbie


Joined: 05 May 2009
Posts: 45

Posted: 29 Apr 2010 01:04:32 am    Post subject:

Graphmastur wrote:

I will use one of the other methods, if they can give me completely accurate. Is this possible?

Graphmastur, if you want your result to be completely accurate, you will have to take just as many steps as calculating the factorial the original way, unless you used a slightly sped-up version. Or possibly some of these.

Is it really that important to get the exact value? This can't be necessary.

Remember that we must sacrifice some things to make up for speed. Accuracy meets this case.
Back to top
thornahawk
μολών λαβέ


Active Member


Joined: 27 Mar 2005
Posts: 569

Posted: 29 Apr 2010 01:20:58 am    Post subject:

Think of gamma like the other more common transcendentals: sin(1) and ln(2) are never exactly computed, be it Java or some other programming language; these quantities are (usually) computed up to the number of significant figures the machine supports. Since the gamma function is rational only for nonnegative integers, you can only approximate it.

Which brings me to the question that should have been asked right off the bat in the very first reply: why exactly do you need a gamma function. Usually computing it only comes up in the context of computing a more complicated function in a lot of applications. What are you trying to compute, and how does gamma enter that picture?

thornahawk

P.S. I've alluded to P. Luschny's work in a number of my previous posts (including some of my posts related to computing the gamma function); do have a peek at his site.
Back to top
Graphmastur


Advanced Member


Joined: 25 Mar 2009
Posts: 360

Posted: 29 Apr 2010 06:28:35 am    Post subject:

thornahawk wrote:

Think of gamma like the other more common transcendentals: sin(1) and ln(2) are never exactly computed, be it Java or some other programming language; these quantities are (usually) computed up to the number of significant figures the machine supports. Since the gamma function is rational only for nonnegative integers, you can only approximate it.

Which brings me to the question that should have been asked right off the bat in the very first reply: why exactly do you need a gamma function. Usually computing it only comes up in the context of computing a more complicated function in a lot of applications. What are you trying to compute, and how does gamma enter that picture?

thornahawk

P.S. I've alluded to P. Luschny's work in a number of my previous posts (including some of my posts related to computing the gamma function); do have a peek at his site.

Well, the majority, if not all of the factors need to be correct. I've also looked into luschny's work. I figured out how to solve this with Riemann sums, but is there afaster way to solve the integral? (please don't refer me to any other algorithms at this time. I simply want to find the answer to this integral now.)
Back to top
thornahawk
μολών λαβέ


Active Member


Joined: 27 Mar 2005
Posts: 569

Posted: 29 Apr 2010 08:33:26 am    Post subject:

Frankly, your insistence on quadrature tells me you've never even attempted to graph the function you're trying to integrate. 'cause, a good look at the graph alone would have told me that even the most sophisticated adaptive quadrature scheme would fare just as badly as a simple Riemann sum. Trying to pretend a decidedly ill-behaved function can be adequately represented as a (piecewise) polynomial has never ended well.

I have no further advice to give; I think I have done my utmost here, and there seems to be no dissuading you. I can only hope whatever lessons you learn from attempting this exercise are not easily forgotten.

Cordially,

thornahawk
Back to top
Display posts from previous:   
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
    »
» View previous topic :: View next topic  
Page 1 of 1 » All times are GMT - 5 Hours

 

Advertisement