Search code examples
matlabzeroexponential

Why does this exponential equation return an all-zero array?


I am trying to figure out why I am getting all zeros back in the code below.

a = 7.0e16;
e = 100000;
r = 8.3140;
t = 253:2:325;

k = a.*exp(-e./t.*r);

k returns as 1x37 array consisting of only zeros.

Is it because my numbers are too large or too small?


Solution

  • You are getting underflow. Things become zero in the exp, and multiplying by a big number afterwards is too late. It looks like a physics equation - in which case you want to divide by r, not multiply. Try

    exp(log(a)-e./(t*r))

    It should work

    EDIT - have to add, not multiply, log(a) in the exponent...