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

조회 수: 8 (최근 30일)
Waseem Akhtar
Waseem Akhtar 2021년 3월 1일
편집: Walter Roberson 2021년 3월 3일
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
Waseem Akhtar
Waseem Akhtar 2021년 3월 3일
@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 2021년 3월 3일
ok so the problem is find why f1 has infinite values - at which iteration does it appear ?

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Special Functions에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by