How to calculate an integral from 0 to infinite

Hi, there!

I wanna to calculate an integral from 0 to infinite , so i use this command
integrate1D( userFunc, 0, inf, 2, 0).

but the result was NaN, when i use a number 2 or any other limited variable to replace "inf", the result was right, so, i think maybe i have use "inf" in a wrong way. Does anyone know how to figure out this problem?


Thanks!
the userFunction is a little complex, so i write a simple one,
function userFunc(xx)
variable xx
variable yy
yy = sin(xx)
return yy
end

function aa()
variable temp = 0
//print integrate1D( xx, 0, 1/temp, 2, 0  )
print integrate1D(userFunc, 0, inf, 2, 0 )
end


I tried to use 1/0 to replace inf, but it doesn't work.
The function in your example does not converge when approaching inf. So NaN would be the correct answer.
Could you check whether your original function is defined at inf or maybe post it?

HJ
Lucas wrote:

I tried to use 1/0 to replace inf, but it doesn't work.


I think you need to recalibrate your notion of numerical integration. You NEVER use INF in numerical integration.

If you have infinite limit(s) in an integration problem start by quitting IGOR and take a piece of paper. Write out your integral and scale it. Simplify the integrand to the extent possible and inspect the behavior in the range of integration. If your integral converges then you should be able to replace the infinite limit with some finite (possibly large) number. Another approach that is frequently employed is a change of variable that transforms an infinite limit to a finite number.

A.G.
WaveMetrics, Inc.
Igor wrote:
Lucas wrote:

I tried to use 1/0 to replace inf, but it doesn't work.


I think you need to recalibrate your notion of numerical integration. You NEVER use INF in numerical integration.

If you have infinite limit(s) in an integration problem start by quitting IGOR and take a piece of paper. Write out your integral and scale it. Simplify the integrand to the extent possible and inspect the behavior in the range of integration. If your integral converges then you should be able to replace the infinite limit with some finite (possibly large) number. Another approach that is frequently employed is a change of variable that transforms an infinite limit to a finite number.

A.G.
WaveMetrics, Inc.



Thanks, A. G. . You really inspire me. I will try that right now. >_<


Igor wrote:
Lucas wrote:

I tried to use 1/0 to replace inf, but it doesn't work.


I think you need to recalibrate your notion of numerical integration. You NEVER use INF in numerical integration.

If you have infinite limit(s) in an integration problem start by quitting IGOR and take a piece of paper. Write out your integral and scale it. ...


Alternatively, open a symbolic math application (e.g. Maple or Mathematica or equivalent). Type in your integral. Use the functional methods in the math application to determine whether the integral of the function over the range needed has a closed-form, analytical expression or a limiting approximation.

:-)

--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAHuntsville