0
$\begingroup$

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,

$\endgroup$
  • 1
    $\begingroup$ 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. $\endgroup$ – cpraveen Nov 1 '17 at 3:47
  • 3
    $\begingroup$ 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. $\endgroup$ – Memming Nov 1 '17 at 13:36
  • $\begingroup$ @PraveenChandrashekar Did you use expm1? $\endgroup$ – Federico Poloni Nov 2 '17 at 20:06
  • $\begingroup$ @PraveenChandrashekar It should optimize to some floating point operand. If it doesn't, what if you would substitute it with logarithm + multiplication? $\endgroup$ – user9927 Nov 4 '17 at 12:55
13
$\begingroup$

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.

As for physical harm: No, computers are designed for this kind of work. There is no need to worry about the computer; you may have to worry about getting your knees too warm, though :-)

$\endgroup$
  • $\begingroup$ Yes, I would guess that adding an exponential term is an easy way to make any system stiff and would guess that this fact is the main cause of sending it from easily computable -> hard to compute. $\endgroup$ – Chris Rackauckas Nov 1 '17 at 6:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.