Page 1 of 1

Integration function - dynare v4?

PostPosted: Tue Sep 15, 2009 9:48 am
by cel
Hi everyone,

Is it possible to use the matlab function 'quad' (which evaluates integral) with Dynare 4?
ps : please, find in the attached file the .mod program, it runs with dynare 3 and not dynare 4, the error message is:
UnknownFunctionNode::eval: operation impossible!
error: the variable or parameter (Hauc) has not been initialized (in derivatives evaluation)
(...)
ERROR: WelfACT.mod:141.22-25: syntax error, unexpected NAME, expecting INT_NUMBER or MINUS or PLUS

Thanks!
Céline

Re: Integration function - dynare v4?

PostPosted: Tue Sep 15, 2009 10:24 am
by SébastienVillemot
Hi,

At this time it is impossible to use this function in the model block (although it should be possible to use it outside the model block).

Only a restricted set of functions is allowed at this time in the model block (see the reference manual), because Dynare 4 needs to know the analytical derivative of the function (contrary to Dynare 3 which does numerical derivation).

We are going to add in a future version of Dynare the possibility of declaring an arbitrary function and its analytical derivative.

So for the moment you must stick to Dynare 3 for your specific problem.

Best,

Re: Integration function - dynare v4?

PostPosted: Tue Sep 15, 2009 11:36 am
by cel
Thanks Sébastien for this quick reply.
One last question: With this program, firstly, I compute analytically the initial steady state of the model and secondly, I assume that one structural parameter is modified (let assume that it is hitten by a deterministic shock). So, I ask to Dynare to compute the final steady state with a new value of the parameter.
By using dynare v3 and:
- 'steady(solve_algo=3)', the new ss is exactly the same that the initial one (which is weird, since the change in the parameter should have changed the ss values),
- 'steady(solve_algo=0)', the new ss is different.
Do you know how this diffence of results can be explained? Can I trust the results provided by the algorithm used in fsolve?

Thanks again,
Céline

Re: Integration function - dynare v4?

PostPosted: Mon Sep 21, 2009 8:54 am
by SébastienVillemot
Hi,

I don't think that solve_algo=3 exists in Dynare v3. It was probably introduced in version 4. So in version 3, with solve_algo=3, the steady command does nothing.

Best,

Re: Integration function - dynare v4?

PostPosted: Mon Sep 21, 2009 10:17 am
by cel
ok, i see, sorry for the silly question then :-)
Thanks again, have a nice day,
Best
Céline

Re: Integration function - dynare v4?

PostPosted: Fri Jul 04, 2014 5:10 pm
by quiko
Since this post dates back to 2009, I was wondering wether some progress have been made with this respect.

I am currently using Dynare 4.2.0/4.4.0 and when I write:

x = quad(@iota,v,5); with iota being a function defined in an .m file, I get: "character unrecognized by lexer". I have also used:

function_handle = @iota;
x = quad(function_handle,v,5); and declared function_handle into the list of variables by I get the same error.

I have read the one could go back to version 3 where the first option should work. But I am on a OSX and looks like there is no version 3 for this operation system.

Any suggestion?

Thanks.

Re: Integration function - dynare v4?

PostPosted: Mon Jul 07, 2014 8:31 am
by jpfeifer
You need two steps:

1. Write a wrapper function that only takes v as an input argument and use this as the external function for Dynare. Within this wrapper function, include the call to
Code: Select all
 quad(@iota,v,5)

That way, you hide the problematic function handle to Dynare.
2. You need to specify the derivative of this function to Dynare.

Re: Integration function - dynare v4?

PostPosted: Mon Jul 07, 2014 10:19 am
by quiko
Thank you for your precious replies. I'm not experienced and I would need examples to understand.

In my case iota is:
Code: Select all
function f = iota(epsilon)
global mean sd
f = lognpdf(epsilon,mean,sd);


Would you mind showing how the code would look like or providing some existing reference showing some example about the implementation you suggested?

Re: Integration function - dynare v4?

PostPosted: Tue Jul 08, 2014 6:29 pm
by jpfeifer
I meant to use the two attached files and the code
Code: Select all
external_function(name=integral_iota,nargs=1,first_deriv_provided);

Re: Integration function - dynare v4?

PostPosted: Thu Jul 10, 2014 11:36 am
by quiko
Thank you very much for your help. I tried with those codes, but I get "Unknown symbol: name". I also checked the DynareWiki about the external function http://www.dynare.org/DynareWiki/ExternalFunctions, but I get the same message.

Re: Integration function - dynare v4?

PostPosted: Thu Jul 10, 2014 11:37 am
by jpfeifer
Please post the files.

Re: Integration function - dynare v4?

PostPosted: Thu Jul 10, 2014 8:10 pm
by quiko
Hi Johannes,

I attach the .mod file (please note it's still in progress) and the functions I'm using for some integrals.

Re: Integration function - dynare v4?

PostPosted: Mon Jul 14, 2014 2:40 pm
by jpfeifer
You have to clean up your code. All external function definitions belong before the model block. Moreover, if lambda is an external function, you must not define it as a variable. Finally, you cannot use external functions like variable names, i.e. you cannot call lambda but only lambda(nu).