Could not integral: Infinite or Not-a-Number value encountered
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Chao-Zhen Liu
il 24 Set 2018
Commentato: Walter Roberson
il 2 Ott 2018
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 Commenti
Torsten
il 27 Set 2018
Modificato: Torsten
il 27 Set 2018
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.
Risposta accettata
Walter Roberson
il 30 Set 2018
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 Commenti
Walter Roberson
il 2 Ott 2018
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)
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Calculus in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!