# Is the exponential function, e^x, very expensive to compute in Matlab and harmful to my computer?

Is the exponential function problematic and very expensive to compute in Matlab?

When I write a new term for my model of ODEs that has an exponential term in it, the program almost never finishes debugging, and I hear the fan on my computer go crazy. So I quickly stop debugging and remove that term in my model. And then all is well again.

Will using the exp() function even physically harm my computer, say, for instance, burn out my hard drive?

Thanks,

• Do you know what is the argument of the exponent for which this takes time ? In one of my fortran code, I have found that computing $x^y$ when $x$ is close to 1 is VERY expensive. This seems to be known problem with glibc, see stackoverflow.com/questions/9272155/… and entropymine.com/imageworsener/slowpow. clang seems not to have this problem. – cpraveen Nov 1 '17 at 3:47
• side note: it's funny you are concerned that you are harming your computer. Modern CPUs slow down when they detect it's too hot. – Memming Nov 1 '17 at 13:36
• @PraveenChandrashekar Did you use expm1? – Federico Poloni Nov 2 '17 at 20:06
• @PraveenChandrashekar It should optimize to some floating point operand. If it doesn't, what if you would substitute it with logarithm + multiplication? – user9927 Nov 4 '17 at 12:55

Computing the term $e^x$ is definitely significantly more expensive than computing a lower-order polynomial -- say $x^4$. But it may be ten to 100 times more expensive at most, not "crazy" expensive. So I suspect that if Matlab takes forever to compute something, then that's because the character of your ODE changes significantly. For example, the presence of that term may make your ODE "stiff" and require a significantly smaller time step than otherwise. That would mean that it's not the evaluation of the right hand side that's expensive, but simply that you need to do many more time steps.