Integration function - dynare v4?

This forum is closed. You can read the posts but cannot write. We have migrated the forum to a new location where you will have to reset your password.
Forum rules
This forum is closed. You can read the posts but cannot write. We have migrated the forum to a new location (https://forum.dynare.org) where you will have to reset your password.

Integration function - dynare v4?

Postby cel » Tue Sep 15, 2009 9:48 am

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
Attachments
test.zip
(2.16 KiB) Downloaded 158 times
cel
 
Posts: 17
Joined: Tue Sep 15, 2009 9:25 am

Re: Integration function - dynare v4?

Postby SébastienVillemot » Tue Sep 15, 2009 10:24 am

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,
Sébastien Villemot
Economist at OFCE – Sciences Po
SébastienVillemot
 
Posts: 706
Joined: Fri Dec 07, 2007 2:29 pm
Location: Paris, France

Re: Integration function - dynare v4?

Postby cel » Tue Sep 15, 2009 11:36 am

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
cel
 
Posts: 17
Joined: Tue Sep 15, 2009 9:25 am

Re: Integration function - dynare v4?

Postby SébastienVillemot » Mon Sep 21, 2009 8:54 am

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,
Sébastien Villemot
Economist at OFCE – Sciences Po
SébastienVillemot
 
Posts: 706
Joined: Fri Dec 07, 2007 2:29 pm
Location: Paris, France

Re: Integration function - dynare v4?

Postby cel » Mon Sep 21, 2009 10:17 am

ok, i see, sorry for the silly question then :-)
Thanks again, have a nice day,
Best
Céline
cel
 
Posts: 17
Joined: Tue Sep 15, 2009 9:25 am

Re: Integration function - dynare v4?

Postby quiko » Fri Jul 04, 2014 5:10 pm

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.
quiko
 
Posts: 17
Joined: Sat Mar 29, 2014 11:06 pm

Re: Integration function - dynare v4?

Postby jpfeifer » Mon Jul 07, 2014 8:31 am

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.
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

Re: Integration function - dynare v4?

Postby quiko » Mon Jul 07, 2014 10:19 am

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?
quiko
 
Posts: 17
Joined: Sat Mar 29, 2014 11:06 pm

Re: Integration function - dynare v4?

Postby jpfeifer » Tue Jul 08, 2014 6:29 pm

I meant to use the two attached files and the code
Code: Select all
external_function(name=integral_iota,nargs=1,first_deriv_provided);
Attachments
iota.m
Function to be integrated
(86 Bytes) Downloaded 141 times
integral_iota.m
Wrapper function that computes the intregral and hides the called function from Dynare. Takes only one input, v
(255 Bytes) Downloaded 141 times
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

Re: Integration function - dynare v4?

Postby quiko » Thu Jul 10, 2014 11:36 am

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.
quiko
 
Posts: 17
Joined: Sat Mar 29, 2014 11:06 pm

Re: Integration function - dynare v4?

Postby jpfeifer » Thu Jul 10, 2014 11:37 am

Please post the files.
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany

Re: Integration function - dynare v4?

Postby quiko » Thu Jul 10, 2014 8:10 pm

Hi Johannes,

I attach the .mod file (please note it's still in progress) and the functions I'm using for some integrals.
Attachments
g2.m
(138 Bytes) Downloaded 90 times
g.m
(80 Bytes) Downloaded 104 times
lambda2.m
(200 Bytes) Downloaded 85 times
lambda.m
(195 Bytes) Downloaded 89 times
model2.mod
(2.04 KiB) Downloaded 112 times
quiko
 
Posts: 17
Joined: Sat Mar 29, 2014 11:06 pm

Re: Integration function - dynare v4?

Postby jpfeifer » Mon Jul 14, 2014 2:40 pm

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).
------------
Johannes Pfeifer
University of Cologne
https://sites.google.com/site/pfeiferecon/
jpfeifer
 
Posts: 6940
Joined: Sun Feb 21, 2010 4:02 pm
Location: Cologne, Germany


Return to Dynare help

Who is online

Users browsing this forum: No registered users and 4 guests