On 10/25/10 11:32 AM, andrew ewart wrote:


f = z*x^3+x*y^3+y*z^3;
H = f.diff(2)

If you can just treat f as a symbolic polynomial, you can use the symbolic expressions to compute the hessian. Here are several ways to do this:

sage: f(x,y,z) = z*x^3+x*y^3+y*z^3 # note this makes x,y,z symbolic variables
sage: f.hessian()
[(x, y, z) |--> 6*x*z (x, y, z) |--> 3*y^2 (x, y, z) |--> 3*x^2]
[(x, y, z) |--> 3*y^2 (x, y, z) |--> 6*x*y (x, y, z) |--> 3*z^2]
[(x, y, z) |--> 3*x^2 (x, y, z) |--> 3*z^2 (x, y, z) |--> 6*y*z]
sage: f.hessian()(x,y,z)
[6*x*z 3*y^2 3*x^2]
[3*y^2 6*x*y 3*z^2]
[3*x^2 3*z^2 6*y*z]
sage: f.diff().diff()
[(x, y, z) |--> 6*x*z (x, y, z) |--> 3*y^2 (x, y, z) |--> 3*x^2]
[(x, y, z) |--> 3*y^2 (x, y, z) |--> 6*x*y (x, y, z) |--> 3*z^2]
[(x, y, z) |--> 3*x^2 (x, y, z) |--> 3*z^2 (x, y, z) |--> 6*y*z]
sage: f.diff().diff()(x,y,z)
[6*x*z 3*y^2 3*x^2]
[3*y^2 6*x*y 3*z^2]
[3*x^2 3*z^2 6*y*z]

sage: var('x,y,z')
(x, y, z)
sage: f = z*x^3+x*y^3+y*z^3;
sage: f.hessian()
[6*x*z 3*y^2 3*x^2]
[3*y^2 6*x*y 3*z^2]
[3*x^2 3*z^2 6*y*z]

Thanks,

Jason

--
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org

Reply via email to