MATLAB: Complex number output vector instead of real output

#complexnumber

Hey all,
I am solving for three equations using given input vector. My input vector is of real numbers. But the output vector is of complex numbers whose complex coefficient is zero. I am unable to understand why Matlab is giving complex output for certain elements even complex term is zero. The code I am analyzing is as follows:
dr=0.055:0.00001:0.063;
for i=1:1:length(dr)
pd=0.015;Fr=8900;Z=9;Kn=3.735e5;
phi1=acos(pd/(2*dr(i)));
epsi=0.5*(1-pd/(2*dr(i)));
f=@(theta)(1/(2*pi)*(1-(0.5/epsi)*(1-cos(theta))).^(1.5).*cos(theta));
Jr(i)=quad(f,-phi1,phi1);
fl(i)=Fr-(Z*Kn*(dr(i)-0.5*pd)^(1.5)*real(Jr(i)));
end;
If we see at the output certain elements of Jr vector are complex. Can somebody tell me why MATLAB is giving answer for certain elements in complex format even if there complex term is zero ? Thanks in advance,
Nikhil

Best Answer

Dear Nikhil, you can use following line of code to see imaginary part of Jones vector
ImaginaryPartofJr = imag(Jr)
and you will see that not all the terms are 0 but they are very very small values like ~10^-27 but not actually 0 and due to this reason MATLAB showing Jr as array of complex doubles. I hope it answers your confusion. Good luck!