Skip to content

rewrite getPowerDeriv assignments in temporary terms

The current implementation has significant overhead to make sure that for integer exponents p the derivative evaluated at 0 returns the correct 0 instead of NaN. For example, the third derivative of x^2 at x=0 needs to evaluate to 0 and not to NaN due to 0^{2-3}=1/x=1/0

From Stephane:

In models with power functions of the form x**a (utility functions, production functions, agregation functions, quadratic costs, ...) the evaluation of the jacobian matrix (or higher order derivates) necessitate potentially a huge number of calls to the routine getPowerDeriv (the name of the routine is explicit enough). In my example (a real business cycle model with perfect foresight) most of the time is spent in this routine, while, if my understanding is correct, this is not necessary because x>0.

I wrote a mex file (see the new branch called mex-!GetPowerDeriv) as a replacement for the matlab routine, unfortunatly the overhead cost is so high that the use of the mex file increases the total time of execution!

In my case I resolved the issue by using option use_dll, but this is not a solution for the majority of our users (they would have to install cygwin/gcc and configure matlab/mex). So my question is: Do we really need to call this routine in all situations ? Would it not be possible to replace calls to this routine by something like:

if (abs(x)>1e-12) tmp = ANALYTICAL_EXPRESSION_OF_THE_DERIVATIVEx,params; else tmp = 0; end

Edited by Johannes Pfeifer