external functions

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.

external functions

Postby Guangye » Tue Apr 08, 2014 8:54 pm

Dear all,

I'm a novice at using Dynare and I'd greatly appreciate any suggestions you might have regarding this possibly simple problem. I'd like to use a standard matlab function (nthroot), but Dynare doesn't support it. I want to calculate an odd number root of a negative number (for example (-1)^(1/3)), but typing (-1)^(1/3) gives 0.5+0.0866i. To get -1, I need to use the nthroot function. So I can I use it in Dynare?

I tried following the instructions in the Dynare guide by creating a function called root which uses nthroot to do the calculation, and declared root in the mod file with "external_function(name = root,nargs = 3);" before using the function in one of the model equations. However I got this error "terminate called after throwing an instance of 'ExternalFunctionNode::UnknownFunctionNameAndArgs'".

Attached are the mod and m files. The function is declared after the block of parameters, and it's the last model equation (taud = root((d(-1)/(p_N^(1-gamma))),(k1/k2),tau);) that uses the root function.

Thank you in advance for your help!
Attachments
root.m
(60 Bytes) Downloaded 65 times
basicmodel3.mod
(3.73 KiB) Downloaded 83 times
Guangye
 
Posts: 3
Joined: Thu Mar 27, 2014 3:22 am

Re: external functions

Postby jpfeifer » Wed Apr 09, 2014 8:35 am

There has been a bug related to external functions in 4.4.2. Please try the most recent unstable version and report back.
------------
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: external functions

Postby Guangye » Thu Apr 10, 2014 3:57 am

Hello Prof. Pfeifer,

Thank you for the reply. I tried the same codes with the unstable version 4.4_2013-10-31 for Mac, and it still isn't working without giving an error message to indicate the cause (model diagnostics did not return anything). Below are the output. Could there be syntactical errors in my attempt to declare the external function? I tried following the manual. Anything suggestion would be greatly appreciated! Thank you!

"/Applications/Dynare/4.4_2013-10-31/matlab/dynare_m" basicmodel3.mod: Bus error
Starting Dynare (version 4.4-unstable).
Starting preprocessing of the model file ...
Found 14 equation(s).
Evaluating expressions...done
Computing static model derivatives:
- order 1
Computing dynamic model derivatives:
- order 1
- order 2

Error using dynare (line 141)
DYNARE: preprocessing failed
Guangye
 
Posts: 3
Joined: Thu Mar 27, 2014 3:22 am

Re: external functions

Postby HoutanBastani » Thu Apr 10, 2014 10:12 am

Several things:

1) This is a bug with the Mac snapshot and, unfortunately, more recent versions of the snapshot don't exist for lack of resources.

2) The external functions fix was made after 31 October, so you need a more recent build

3) Out of curiosity, what version of OS X are you using? Anyway, you can build Dynare on your computer following the instructions here (under Mac OS X): https://github.com/DynareTeam/dynare

4) You don't need the root function. Just declare an externalfunction called nthroot, as in:
Code: Select all
external_function(name = nthroot,nargs = 2);

Replace line 81 with:
Code: Select all
taud = tau*nthroot((d(-1)/(p_N^(1-gamma))),(k1/k2));

and delete root.m
Best,
Houtan
HoutanBastani
 
Posts: 197
Joined: Fri Jan 22, 2010 4:11 pm
Location: Paris, France

Re: external functions

Postby Guangye » Mon Apr 21, 2014 7:14 pm

Thank you very Houtan.

I have OS X 10.8.5, but we ended up compiling Dynare on a cluster and now the external function is working. However, Dynare cannot find the steady state, it's giving the following error whenever I try to take a root of greater than 1 with the nthroot external function:
"
Error using print_info (line 74)
Impossible to find the steady state. Either the model doesn't have a steady state, there are
an infinity of steady states, or the guess values are too far from the solution
"
Is that because there's still something wrong with the external function, or because one of my equations is wrong? I attached the mod file.

Thank you so much, I really appreciate your help!

Guangye
Attachments
basicmodel3.mod
(3.78 KiB) Downloaded 70 times
Guangye
 
Posts: 3
Joined: Thu Mar 27, 2014 3:22 am

Re: external functions

Postby jpfeifer » Wed May 07, 2014 9:02 am

It seems you just need to provide better starting values. If you put resid before steady you will see that particularly equation 9 has a big residual.
------------
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: Google [Bot] and 6 guests