Ask Your Question
0

Expression of the hessian of a lagrangian

asked 2023-04-30 15:43:59 +0100

Cyrille gravatar image

When I ask for the hessian of L in the following code, SageMath returns the functions of the derivatives as $(x,y,\lambda) \rightarrow expression\ of \ f_{xx}$ for example. But I need only $f_{xx}$. What can I do ?

I have search for hessian? but there is no entry in the online documentation.

 varx=var('x y') 
paramu=var('A α β U')
paramuc=tuple(list(paramu)+[U])
paramb=var('R p_x p_y')
varl=var('λ')
varg=tuple(list(varx)+[λ])

def Cobb_Douglas(x, y, A, α, β) :
    return A*x^α*y^β

def expense(x,y,p_x,p_y) :
    return p_x*x+ p_y*y

L(x,y,λ) = Cobb_Douglas(x,y,A, α, β) -λ*(expense(x,y,p_x,p_y)-R)
L.hessian()
edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2023-05-01 02:03:00 +0100

Emmanuel Charpentier gravatar image

updated 2023-05-01 02:22:14 +0100

You get a matrix of functions :

sage: L.hessian().parent()
Full MatrixSpace of 3 by 3 dense matrices over Callable function ring with arguments (x, y, λ)

Apply them :

sage: L.hessian()(x, y, λ)
[A*x^(α - 2)*y^β*(α - 1)*α A*x^(α - 1)*y^(β - 1)*α*β                      -p_x]
[A*x^(α - 1)*y^(β - 1)*α*β A*x^α*y^(β - 2)*(β - 1)*β                      -p_y]
[                     -p_x                      -p_y                         0]

NOTE : The peculiar Mathjax interpreter of this site does not typeset this correctly (ignores the linebreaks). LaTeX does (provided you replace the non-ASCII variable names wit their conventional replacement... or you use XeLaTeX to typeset...). Trying HTML is no more successful (same problem).

I have search for hessian? but there is no entry in the online documentation.

L.hessian? prints :

Docstring:     
   Compute the hessian of a function. This returns a matrix components
   are the 2nd partial derivatives of the original function.

   EXAMPLES:

      sage: x,y = var('x y')
      sage: f = x^2+y^2
      sage: f.hessian()
      [2 0]
      [0 2]
      sage: g(x,y) = x^2+y^2
      sage: g.hessian()
      [(x, y) |--> 2 (x, y) |--> 0]
      [(x, y) |--> 0 (x, y) |--> 2]
Init docstring: Initialize self.  See help(type(self)) for accurate signature.
File:           /usr/local/sage-10/src/sage/symbolic/expression.pyx
Type:           builtin_function_or_method

HTH,

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2023-04-30 15:43:59 +0100

Seen: 244 times

Last updated: May 01 '23