NaN Solution Problem with erfi() and erf()
1 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
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
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!