Ask Your Question
1

How to do symbolic vector/matrix manipulations in Sage?

asked 2014-02-17 05:35:27 -0500

Gravitus gravatar image

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 flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2014-02-17 05:53:17 -0500

tmonteil gravatar image

Does it answers your question ?

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]
edit flag offensive delete link more

Comments

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...

Gravitus gravatar imageGravitus ( 2014-02-17 06:11:30 -0500 )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))

moroplogo gravatar imagemoroplogo ( 2014-02-19 08:59:58 -0500 )edit

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: 2014-02-17 05:35:27 -0500

Seen: 244 times

Last updated: Feb 17 '14