필터 지우기
필터 지우기

NaN Solution Problem with erfi() and erf()

조회 수: 5 (최근 30일)
imarquez
imarquez 2015년 8월 6일
편집: Stephen23 2015년 8월 11일
So when I solve for Ff only the first column (1 through 2) is returned with values and the rest are NaN and all of the values for Zf are NaN. Is there any way that I can get a number value out of these? I need them because I'm trying to graph something.
I have tried using erf() and just making whats inside the erf() function a real number but it isn't coming out like it should that way. Any suggestions?
if true
format long
a = 1
b = 3*10.^-7
c = 5*10.^-8
f0 = 4*10.^9
sigma = 0.2
t0 = 0
tmax = 2*b
t = linspace(t0, tmax)
f = linspace(10.^6, 10.^10)
omega0 = 2*pi*f0
yt = a*exp((-(t-b).^2)/((2*c).^2))
figure(1)
plot(t,yt)
zt = yt.*(1-((sigma/2)*(1-sin(omega0*t))))
figure(2)
plot(t,zt)
G = -2.*pi.*f.*(pi.*c.^2.*f + sqrt(-1).*b)
D = (((b-(sqrt(-1)).*2.*pi.*c.^2.*f-t0)/(sqrt(2).*c)))
E = (((b-(sqrt(-1)).*2.*pi.*c.^2.*f-tmax)/(sqrt(2).*c)))
Ff = sqrt(pi/2).*a.*c.*exp(G).*((-sqrt(-1).*(erfi(-sqrt(-1).*D)))-((-sqrt(-1).*(erfi(-sqrt(-1).*E)))))
Zf = ((1-(sigma/2)).*Ff) + (sqrt(-1).*sqrt(pi/2).*((a.*c.*sigma)/4).*exp(-((2.*pi.*f+omega0).*(c.^2.*(2.*pi.*f+omega0)+2.*sqrt(-1).*b)))).*(-exp(4.*pi.*c.^2.*f.*omega0+2.*sqrt(-1).*b.*omega0).*((-sqrt(-1).*erfi(((tmax-b+sqrt(-1).*c.^2).*(2.*pi.*f-omega0))/(sqrt(2).*c)))-(-sqrt(-1).*erfi(((t0-b+sqrt(-1).*c.^2).*(2.*pi.*f-omega0))/(sqrt(2).*c))))+(-sqrt(-1).*(erfi(((tmax-b+sqrt(-1)*c.^2).*(2.*pi.*f+omega0))/(sqrt(-1).*c))))-(-sqrt(-1).*erfi(((t0-b+sqrt(-1).*c.^2).*(2.*pi.*f+omega0))/(sqrt(-1).*c))))
figure(3)
plot(f,Zf)
% code
end

채택된 답변

Ghada Saleh
Ghada Saleh 2015년 8월 11일
Hi Imarquez,
The issue you encountered is not because of 'erfi', it is because you are exceeding the maximum floating number that can be represented in MATLAB. Basically you are computing 'inf-inf' which results in 'NAN'. The 'inf' is a result of calculating 'erfi(c)' where 'c' is some large number. Note that the definition of 'erfi' is an integration of exponential square. To see that, try the following command in MATLAB:
>> exp(200^2)
ans =
Inf
Hence,
>> erfi(200)
ans =
Inf
since, in the calculation in 'Ff' and 'Zf' you have 'inf - inf', you end up with 'NAN' value.
I hope this helps,
Ghada
  댓글 수: 2
imarquez
imarquez 2015년 8월 11일
That makes a lot of sense now. This is a long shot, but do you know if excel will be able to return a value based on the same calculation?
Stephen23
Stephen23 2015년 8월 11일
편집: Stephen23 2015년 8월 11일
Consider how large those numbers would be, and read this:

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by