MATLAB: Why i receive Nan for integral -inf to -inf

for example:
if true
integral(@(x)exp(-(x.^2)/2),-inf,-inf)
end

Best Answer

The integral from -inf to -inf over exp(-(x.^2)/2) is the same as calculating the area of the rectangle bounded by -inf and -inf with a height e(-(x.^2)/2) evaluated at -inf(which is 0).The difference between -infs will return an NaN in MATLAB . The NaN times the height(0) results in NaN as well. The documentation link for properties of NaN : https://www.mathworks.com/help/matlab/ref/nan.html