Could not integral: Infinite or Not-a-Number value encountered
5 次查看(过去 30 天)
显示 更早的评论
Hi everyone,
Does anyone can tell me what's wrong with my code? I always receives the warnings:
Warning: Infinite or Not-a-Number value encountered.
U = 14; L = 7; d = (U-L)/2;
d_star = d;
T = ( U+L )/(1+1); % symmeric
alpha = 0.10;
Le = 0.05;
for kursi = [0 0.25 0.5 1 2 3]
sigma = fzero( @(sigma) Le - (sigma./d)^2 - ( kursi.*sigma./d).^2, 1 ) ;
mu = kursi*sigma + T;
j = 1;
for n = [25 50 100 150 200]
delta = ( n.^(1/2) ).*kursi ;
B = (n*d_star^2)/sigma^2;
i= 1;
for x = 7:0.01:14
sample = normrnd(mu,sigma,1,n);
% fK = ( 2^(-(n-1)/2)/gamma((n-1)/2) ).*((B.*x.*(1-t)).^(n-3)/2 ).*exp(-B.*x.*(1-t)/2);
fun = @(t) ( sqrt( (B^3).*x./t )./2 ).*( ( 2^(-(n-1)/2) / gamma((n-1)/2) ).*( (B.*x.*(1-t)).^((n-3)/2) ).*exp(-B.*x.*(1-t)/2) ).*( normpdf(sqrt(B*x*T)+delta,0,1) + normpdf(sqrt(B*x*T)-delta,0,1) );
pdf_Lehat(j,i) = integral(@(t) fun(t),0,1);
i = i + 1;
end
j = j + 1;
end
end
x = 7:0.01:14;
plot(x, pdf_Lehat(1,:)); hold on
plot(x, pdf_Lehat(2,:)); hold on
plot(x, pdf_Lehat(3,:)); hold on
plot(x, pdf_Lehat(4,:)); hold on
plot(x, pdf_Lehat(5,:)); hold on
xlabel('X')
I guess the problem may be the handle ,fun, especially the mid part of the code (i.e. the above code, fK). Hope you can give me some advice, thanks!
9 个评论
Torsten
2018-9-27
编辑:Torsten
2018-9-27
In the evaluation of plotfun, you use B=4.0e4, x=14, n=200 and T=10.5.
Now specify a value for t and evaluate all parts of "plotfun" separately for these parameter values for B,x,n and T. See where there might be problems in the evaluation (e.g. gamma((n-1)/2)= gamma(199/2) seems too huge, 2^(-(n-1)/2)=2^(-199/2) seems too small).
Best wishes
Torsten.
采纳的回答
Walter Roberson
2018-9-30
The values of your integral are so small that they cannot be represented in double precision, and can barely be represented in the Symbolic Toolbox either. Values like 2*10^(-87012)
12 个评论
Walter Roberson
2018-10-2
Your term exp(-B.*x.*(1-t)/2) is responsible. The -B*x/2 is coming out at about 35000 and the 1-t flips that to about exp(-35000 *t)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Calculus 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!