improper integral

15 次查看(过去 30 天)
kostas
kostas 2011-4-5
Hi!!I need help in the calculation of the integral of the function below
function out = fun(u,a,b)
out = exp(-a.* exp(2.*u)).*exp(-(u + b.^2).^2./2.*b.^2)/...
(sqrt(2.*pi.*b.^2));
end
a=0; b=1; *quad('fun',-Inf,Inf,[],[],a,b);
Is there any idea? where is the mistake?
  3 个评论
Asatur Khurshudyan
Asatur Khurshudyan 2012-12-30
I guess you have to calculate the principal value (by Cauchy) of that integral, otherwise you`ll have Nan`s or Infinity`s. I also have such a problem with 3D plotting improper integrals with infinite upper limit. Have anyone did something like that?
Roger Stafford
Roger Stafford 2012-12-30
For a = 0 this becomes just the integral of a normal distribution density function over its full range, and of course it must then be equal to 1. It is when a is greater than zero that the integral becomes more interesting. For negative a the integral is divergent.

请先登录,再进行评论。

采纳的回答

Andrew Newell
Andrew Newell 2011-4-5
I don't think quad ever allowed infinite limits. quadgk does. The answer you need depends on how old your MATLAB version is. I am going to express an answer in more recent syntax. If you try
a=0; b=1;
fun = @(u) exp(-a.* exp(2.*u)).*exp(-(u + b.^2).^2./2.*b.^2)/...
(sqrt(2.*pi.*b.^2));
quad(fun,-Inf,Inf)
then you get this message:
Warning: Infinite or Not-a-Number function value encountered.
and the answer is NaN. The likely reason is that there is underflow in these exponential expressions:
>> fun(1000)
ans =
NaN
However, if you plot this function, you can see that this function approaches zero very rapidly. For example,
>> fun(0)
ans =
0
Therefore, you can do this calculation:
quadl(fun,-100,100)
ans =
1.0000
This is 1 to an accuracy of about 10^-8.
Note: the fun = ... line is an anonymous function.

更多回答(1 个)

Matt Fig
Matt Fig 2011-4-5
quadgk(@(x) fun(x,0,1),-inf,inf) % 0 is a, 1 is b.
But for a = 0, b = 1, we encounter an infinite number or nan. Are these numbers correct? If so, you could try this:
quadgk(@(x) fun(x,0,1),-10,10) % Exponentially decreasing values.
Or look at QUADL.
quadl(@(x) fun(x,0,1),-200,200,1e-15)

类别

Help CenterFile Exchange 中查找有关 Numerical Integration and Differentiation 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by