ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 19 Feb 2014 15:59:58 +0100How to do symbolic vector/matrix manipulations in Sage?https://ask.sagemath.org/question/11050/how-to-do-symbolic-vectormatrix-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. Mon, 17 Feb 2014 12:35:27 +0100https://ask.sagemath.org/question/11050/how-to-do-symbolic-vectormatrix-manipulations-in-sage/Answer by tmonteil for <p>Hello, </p>
<p>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.</p>
<p>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}$. </p>
<p>Is there such a way? Thanks. </p>
https://ask.sagemath.org/question/11050/how-to-do-symbolic-vectormatrix-manipulations-in-sage/?answer=16058#post-id-16058Does 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]
Mon, 17 Feb 2014 12:53:17 +0100https://ask.sagemath.org/question/11050/how-to-do-symbolic-vectormatrix-manipulations-in-sage/?answer=16058#post-id-16058Comment by moroplogo for <p>Does it answers your question ?</p>
<pre><code>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]
</code></pre>
https://ask.sagemath.org/question/11050/how-to-do-symbolic-vectormatrix-manipulations-in-sage/?comment=16236#post-id-16236you 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)) Wed, 19 Feb 2014 15:59:58 +0100https://ask.sagemath.org/question/11050/how-to-do-symbolic-vectormatrix-manipulations-in-sage/?comment=16236#post-id-16236Comment by Gravitus for <p>Does it answers your question ?</p>
<pre><code>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]
</code></pre>
https://ask.sagemath.org/question/11050/how-to-do-symbolic-vectormatrix-manipulations-in-sage/?comment=16246#post-id-16246Almost, 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...Mon, 17 Feb 2014 13:11:30 +0100https://ask.sagemath.org/question/11050/how-to-do-symbolic-vectormatrix-manipulations-in-sage/?comment=16246#post-id-16246