Azzera filtri
Azzera filtri

Warning: Infinite or Not-a-Number value encountered.

15 visualizzazioni (ultimi 30 giorni)
Dear all,
I am facing the warning (Infinite or Not-a-Number value encountered.) in my following code. Due to the Nan/Inf values, the output of my complete code is erratic. Please help me solve the issue, thanks. Body of affected portion of code is as under:
clear all
clc
AB=0.34;
j=1;
x(1)=(15*AB);
z(1)=0;
while z <= 0.3
j=j+1;
z(j)=z(j-1)+0.020;
i=1;
while x(i)<=(15*AB) && x(i)>=(-15*AB)
i=i+1;
x(i)=x(i-1)-(AB/10);
f1=@(l)exp(-(x(i)/1000-l.*cos(0.2663)).*(1.67./ (2.*4.18e-6))).*(besselk(0,((1.67./(2.*4.18e-6)).*sqrt((x(i)/1000-l.*cos(0.2663)).^2+(z(j)/1000+l.* sin(0.2663)).^2))));
% Lower limit of integral
a=0.000001;
% Upper limit of integral
b=AB/1000;
integral1(i)=integral(f1,a,b);
end
end
  3 Commenti
Waseem Akhtar
Waseem Akhtar il 3 Mar 2021
@Mathieu NOE Thank you for your comment.
I checked the part you mentioned which is a Modified Bessel function but the formulation or values seem to be ok.
I also tried to split the function in two parts as follows:
''
f1=@(l)exp(-(x(i)/1000-l.*cos(0.2663)).*(1.67./ (2.*4.18e-6)));
f2=@(l)(besselk(0,((1.67./(2.*4.18e-6)).*sqrt((x(i)/1000-l.*cos(0.2663)).^2+(z(j)/1000+l.* sin(0.2663)).^2))));
% Lower limit of integral
a=0.000001;
% Upper limit of integral
b=AB/1000;
integral1(i)=integral(f1,a,b);
integral2(i)=integral(f2,a,b);
value(i)=integral1(i).*integral2(i);
''
I noticed that the first part (f1) has infinite values after certain iterations whereas 2nd part (f2) has finite or zero values. I am not sure if some other integration technique could help. I have also tried "quad fn" and "Simpson's rule" but to no use. I am not sure how to solve this issue :(
Mathieu NOE
Mathieu NOE il 3 Mar 2021
ok so the problem is find why f1 has infinite values - at which iteration does it appear ?

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Special Functions 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!

Translated by