# How to do symbolic vector/matrix manipulations in Sage?

Hello,

So I have a 2x1 vector $\mathbf{x} \in R^2$, and a function on it called $f(\mathbf{x}) = log(\mathbf{1}^T \mathbf{x})$ which of course, returns a scalar.

I would like to compute the Hessian of this function in Sage, symbolically. That is, I would like it so show me what the 2x2 Hessian matrix would look like, but in terms of the elements of $x$, or even better, in terms of the vector $\mathbf{x}$.

Is there such a way? Thanks.

edit retag close merge delete

Sort by » oldest newest most voted

sage: x, y = var('x y')
sage: f = log(x+y)
sage: f.hessian()
[-1/(x + y)^2 -1/(x + y)^2]
[-1/(x + y)^2 -1/(x + y)^2]

more

Almost, tmonteil. I would like to know how/if it can show it, in matrix form. For example, instead of declaring x and y as variables, we declare a 2x1 vector x, so it shows the hessian in terms of the _vector_ x...

( 2014-02-17 13:11:30 +0200 )edit

you can try this way. But with no guarantee. sage: from sympy import * sage: from mpmath import * sage: A = MatrixSymbol('A', 1, 2) sage: logm((Identity(2)*transpose(A))

( 2014-02-19 15:59:58 +0200 )edit