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

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?

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?

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?

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?

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

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

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

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');
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

```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

-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');
> 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
>
```

```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??
```

```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
```

```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?
```