MATLAB >> how to calculate the integrand of a function from 0 to infinity?

by hnliuhy » Fri, 28 Jan 2005 08:07:22 GMT

Hi,
How to calculate the integrand for a function from 0 to infinity.

for example

g=inline('exp(-2*x)');
quad(g, 0, infinity) ; % don't know how to do
% this, so, here I just put
% as infinity.

By the way, if

g=inline('exp(-b*x)');

with b unknown, how can I obtain the integrand as a function b by
integrate g over x?

Thanks alot

MATLAB >> how to calculate the integrand of a function from 0 to infinity?

by Steve Irwin » Fri, 28 Jan 2005 08:29:55 GMT



NIP Wants to integrate g=exp(-2*x) from 0>>inf...


syms x
g=exp(-2*x)
int(g,0,inf)

MATLAB >> how to calculate the integrand of a function from 0 to infinity?

by hnliuhy » Fri, 28 Jan 2005 11:11:51 GMT


Hi,
It won't work for me.
>>> syms x
??? syms x
|
Error: Missing operator, comma, or semicolon. >>> g=exp(-2*x)
??? Undefined function or variable 'x'. >>> int(g,0,inf)
??? Undefined function or variable 'g'.

I tried with inline, it won't work either
>>> g=inline('exp(-x)*t^(x-1)')

g =

Inline function:
g(t,x) = exp(-x)*t^(x-1)
>>> int(g,0,inf)
??? Undefined function or variable 'int'.

MATLAB >> how to calculate the integrand of a function from 0 to infinity?

by Steve Irwin » Fri, 28 Jan 2005 12:54:10 GMT


NIPgt;>>>syms x>>>>g=exp(-2*x)>>>>int(g,0,inf)


NIP>
> It won't work for me.

you'll need the symbolic math toolbox for this. it *may* be possible
with "inline", but frankly i've no experience with this.

lata,
steve

MATLAB >> how to calculate the integrand of a function from 0 to infinity?

by Steve Irwin » Fri, 28 Jan 2005 13:13:19 GMT


not an exact solution, but a work-around that *might* be useful...

[C,n]=computer;
g=inline('exp(-2*x)');
quad(g,0,n)

MATLAB >> how to calculate the integrand of a function from 0 to infinity?

by spellucci » Fri, 28 Jan 2005 21:03:26 GMT


In article < XXXX@XXXXX.COM >,
hnliuhy < XXXX@XXXXX.COM > writes:
>Hi,
>How to calculate the integrand for a function from 0 to infinity.
>
>for example
>
>g=inline('exp(-2*x)');
>quad(g, 0, infinity) ; % don't know how to do
> % this, so, here I just put
> % as infinity.
>
>By the way, if
>
>g=inline('exp(-b*x)');
>
>with b unknown, how can I obtain the integrand as a function b by
>integrate g over x?
>
>Thanks alot

g=inline('exp(-b*x)','x','b');
quad(g,0,xend,[],b); %b is an "additional parameter"
you cannot integrate over an infinite interval in matlab. use the transformation
of variables
z=1/(x-x0+1)
for an integral from x0 to infinity . this takes that interval into [0,1]
normally, you now have a singularity at z=0. hence again, current matlab
integrators will not work, but you can have easily one yourself, taking
quadl and exchanging the Lobatto nodes by ordinary Gauss nodes.
needsa little fiddling around, since the interval refinement needs some
modification.
hth
peter

Similar Threads

1. how to calculate the integrand of a function f

Symbolically you can do an infinite interval. Numerically the doubly
infinite integral can be computed using Hermite quadrature. The
[0,inf] integral can be done with Laguerre, or a mapping of some
Jacobi-Radau quadrature.

-G

Peter Spellucci wrote:
>
>
>
> In article < XXXX@XXXXX.COM >,
> hnliuhy < XXXX@XXXXX.COM > writes:
> >Hi,
> >How to calculate the integrand for a function from 0 to
infinity.
> >
> >for example
> >
> >g=inline('exp(-2*x)');
> >quad(g, 0, infinity) ; % don't know how to do
> > % this, so, here I just put
> > % as infinity.
> >
> >By the way, if
> >
> >g=inline('exp(-b*x)');
> >
> >with b unknown, how can I obtain the integrand as a function b
by
> >integrate g over x?
> >
> >Thanks alot
>
> g=inline('exp(-b*x)','x','b');
> quad(g,0,xend,[],b); %b is an "additional parameter"
> you cannot integrate over an infinite interval in matlab. use the
> transformation
> of variables
> z=1/(x-x0+1)
> for an integral from x0 to infinity . this takes that interval into
> [0,1]
> normally, you now have a singularity at z=0. hence again, current
> matlab
> integrators will not work, but you can have easily one yourself,
> taking
> quadl and exchanging the Lobatto nodes by ordinary Gauss nodes.
> needsa little fiddling around, since the interval refinement needs
> some
> modification.
> hth
> peter
>

2. Minimizing functions with an infinity somatorium - MATLAB

3. function works in infinity

Hi.
i have 3 functions
1st: my_fun1.m
2nd: my_fun2.m
3rd: main.m

and in main.m :

fragment of code:
...
...
...
try
   if my_fun1 == my_fun2
      a=1;
   else
      b=0;
   end
catch
   a=0;
end;
...
...
%%%%%%
but is still one problem, if in my_fun1 or my_fun2 is:

c=1;
while c>0
end

in this situation main function will work infinity:(
what can i do in this situation, what should i write in main
function??

4. integration with parameters in integrand.. - MATLAB

5. Help with numerical integration: integrand could not be vectorized

Hello everyone, 

I am trying to do a 2D integration in Matlab, and my integrand is so complicated that it is not possible to vectorize it in a straightforward way, so I have to write a for loop to force the integrand to accept a vector x and a scalar y, which in Matlab will cause huge slow in speed. I am wondering if anyone is aware of how to deal with such problems in Matlab? Many thanks!

Jun

6. Using an embedded MATLAB function to calculate discrete filter transfer function coefficients - MATLAB

7. How to calculate the multiple integral of some complicated integrand?

I encounter an multiple value integrand in some optimization problem, which has the similar forms as follows:
       F(z1, z2, z3) = exp(-(z1+z2+z3-mu)^2)*exp(-(z2+z3-mu)^2)*exp(-(z3-mu)^2)
given the bounds of z1, z2 and z3, how to solve the multiple integration of this integrand in matlab?

8. BVP ODe withconstraints in infinity - MATLAB