Thread Subject: Numerical Integration

Subject: Numerical Integration

From: Saed

Date: 19 Jun, 2009 00:36:01

Message: 1 of 8

Hello,

I have the following function

function Psi_Out = Psi(a,b,z)
Fun=@(t)((1./gamma(a)).*exp(-z.*t).*(t.^(a-1)).*((1+t).^(b-a-1)));
Psi_Out =quad(Fun,0,5000);

where a and b are constants, and z is a sumolic expression. When I run the following commands:

syms s;
Psi(2,2,s.^2+2.*s);

an error occurs. Where did I mistake the function?

Subject: Numerical Integration

From: John D'Errico

Date: 19 Jun, 2009 01:37:01

Message: 2 of 8

"Saed " <dawoudsaed@yahoo.com> wrote in message <h1emhh$mok$1@fred.mathworks.com>...
> Hello,
>
> I have the following function
>
> function Psi_Out = Psi(a,b,z)
> Fun=@(t)((1./gamma(a)).*exp(-z.*t).*(t.^(a-1)).*((1+t).^(b-a-1)));
> Psi_Out =quad(Fun,0,5000);
>
> where a and b are constants, and z is a sumolic expression. When I run the following commands:
>
> syms s;
> Psi(2,2,s.^2+2.*s);
>
> an error occurs. Where did I mistake the function?

Because you are trying to use a numerical integration
(quad) on a symbolic problem.

John

Subject: Numerical Integration

From: vedenev

Date: 19 Jun, 2009 08:44:25

Message: 3 of 8

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/

Subject: Numerical Integration

From: Saed

Date: 19 Jun, 2009 12:07:00

Message: 4 of 8

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.

Subject: Numerical Integration

From: Steven Lord

Date: 19 Jun, 2009 14:02:50

Message: 5 of 8


"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

Subject: Numerical Integration

From: Saed

Date: 19 Jun, 2009 14:16:02

Message: 6 of 8

"Steven Lord" <slord@mathworks.com> wrote in message <h1g5p7$nhp$1@fred.mathworks.com>...
>
> "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
>

Actually it is the Tricomi's Confluent Hypergeometric function, but I don't think it is a build-in function in MATLAB, so I have to define it by myself.

Subject: Numerical Integration

From: Soumendra Datta

Date: 13 Aug, 2009 06:51:01

Message: 7 of 8

"Saed " <dawoudsaed@yahoo.com> wrote in message <h1g6j2$hch$1@fred.mathworks.com>...
> "Steven Lord" <slord@mathworks.com> wrote in message <h1g5p7$nhp$1@fred.mathworks.com>...
> >
> > "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
> >
>
> Actually it is the Tricomi's Confluent Hypergeometric function, but I don't think it is a build-in function in MATLAB, so I have to define it by myself.


Can you please specify how to define Tricomi's Confluent Hypergeometric function as it is not available in MATLAB?
Soumendra

Subject: Numerical Integration

From: Steven Lord

Date: 13 Aug, 2009 13:49:07

Message: 8 of 8


"Soumendra Datta" <soumendra_13@yahoo.co.in> wrote in message
news:h60d4l$g1g$1@fred.mathworks.com...
> "Saed " <dawoudsaed@yahoo.com> wrote in message
> <h1g6j2$hch$1@fred.mathworks.com>...
>> "Steven Lord" <slord@mathworks.com> wrote in message
>> <h1g5p7$nhp$1@fred.mathworks.com>...

*snip*

> Can you please specify how to define Tricomi's Confluent Hypergeometric
> function as it is not available in MATLAB?
> Soumendra

As you may or may not know, you can extend the capabilities of MATLAB by
writing your own function M-files.

http://www.mathworks.com/access/helpdesk/help/techdoc/learn_matlab/f4-2525.html

http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_prog/f7-38012.html

Therefore, to add this functionality to MATLAB, you can find an equation for
this function (Abramowitz & Stegun's Handbook of Mathematical Functions may
list it) and implement that equation in a function M-file. Then you will be
able to use it like any other MATLAB function.

--
Steve Lord
slord@mathworks.com

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
numerical integ... Sprinceana 22 Jun, 2009 04:42:15
rssFeed for this Thread

Contact us at files@mathworks.com