Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: take numerical derivatives in Mata


From   KAI LIU <[email protected]>
To   [email protected]
Subject   st: take numerical derivatives in Mata
Date   Mon, 11 Aug 2008 18:57:31 -0400

Dear statalist users, 

I am seeking help on commands that could take numerical derivative of an arbitrary function v=f(p) in MATA.  For example, I have an optimization routine for function v(p_1, p_2):
void eval0(todo, p, v, g, H)
         {
		m = exp(-p[1]^2 - p[2]^2 - p[1]*p[2] + p[1] - p[2])
		w= p[1]^2
		v=(w-m)^2
         }
         S = optimize_init()
         optimize_init_evaluator(S, &eval0())
         optimize_init_params(S, (0,0))
         p = optimize(S)

The "optimize_result_gradient(S)" command would give gradient vector for function v.  But is there any way to take derivatives with respect to function m() or w(), say at the optimized value of p?  I tried various ways to execute the stata command "dydx" (which takes derivatives in stata environment) under Mata by using stata("dydx m p[1],generate(x)"), and didn't make it work either.  

Really appreciate if someone familiar with mata could give me a hand on this.  Many thanks in advance.

Kai
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index