Path: news.mathworks.com!not-for-mail
From: "Steven Lord" <slord@mathworks.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Numerical Integration
Date: Fri, 19 Jun 2009 10:02:50 -0400
Organization: The MathWorks, Inc.
Lines: 51
Message-ID: <h1g5p7$nhp$1@fred.mathworks.com>
References: <h1emhh$mok$1@fred.mathworks.com> <h1eq3t$6rb$1@fred.mathworks.com> <32ef8539-b42c-447d-8436-f796643fd085@o20g2000vbh.googlegroups.com> <h1fv14$79u$1@fred.mathworks.com>
Reply-To: "Steven Lord" <slord@mathworks.com>
NNTP-Posting-Host: lords.dhcp.mathworks.com
X-Trace: fred.mathworks.com 1245420134 24121 144.212.105.187 (19 Jun 2009 14:02:15 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 19 Jun 2009 14:02:14 +0000 (UTC)
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.5512
X-RFC2646: Format=Flowed; Original
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579
Xref: news.mathworks.com comp.soft-sys.matlab:548932



"Saed " <dawoudsaed@yahoo.com> wrote in message 
news:h1fv14$79u$1@fred.mathworks.com...
> vedenev <vedenev.maxim@gmail.com> wrote in message 
> <32ef8539-b42c-447d-8436-f796643fd085@o20g2000vbh.googlegroups.com>...
>> See, example:
>>
>> syms a b z t
>> Fun=((1./gamma(a)).*exp(-z.*t).*(t.^(a-1)).*((1+t).^(b-a-1)))
>> Psi=int(Fun,t,0,5000)
>>
>> -----------------------------------------
>> Maxim Vedenev, MATLAB Custom Programming
>> vedenev@ngs.ru
>> http://simulations.narod.ru/
>
> But as I know, using anonymous functions followed by quad command, is the 
> quickest way to do integrations. I have a very long expression in term of 
> s, and I tried the way you suggested, but the program takes a considerable 
> amount of time to be executed. So, I need a suggestion in how to use the 
> quad command, or an equivalent fast integration, please.

You have three choices:

1) Perform the integration symbolically using INT on an expression 
containing a symbolic variable.  This will be slower than the second choice.

2) Perform the integration numerically using QUAD (or even better QUADGK) on 
an expression that does NOT contain symbolic variables.  If you use this 
approach, you'll want to integrate only over the region where your function 
is "significantly different from zero" (for some definition of 
"significantly") to make sure that the integration routine can see the 
details of your function.  After all, if you look out an airplane window at 
30,000 feet you're not going to be able to distinguish an individual person 
on the ground -- specifying a very large integration interval where the 
function is mostly zero is similar to that.

3) Look up your integral in a table of integrals, and replace the 
integration with an evaluation of the closed-form solution of that integral. 
This won't work for all integrals, but it's probably going to be the fastest 
of all the methods.

For this particular integral, if you choose choice 3, you'll probably want 
to look for stuff related to the Beta distribution, as the expression you 
wrote looks somewhat similar to the Beta CDF (modulo the exponential term.)

-- 
Steve Lord
slord@mathworks.com