Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23131

How to compute a gradient and a Hessian of a Sympy expression

$
0
0

Let's say we have a Sympy expression:

import sympy as sp a = sp.Symbol('a', real=True)b = sp.Symbol('b', real=True)c = sp.Symbol('c', real=True)f = 0.2*a**3 - 0.1*a**2*b - 0.9*a**2*c + 0.5*a**2 - 0.1*a*b**2 - 0.4*a*b*c + 0.5*a*b - 0.6*a*c**2 - 0.5*a*c - 0.6*a - 0.1*b**3 + 0.4*b**2*c - 0.4*b**2 + 0.7*b*c**2 - 0.4*b*c +0.9*b + 0.09*c**3 - 0.6*c**2 + 0.4*c + 0.22

How to get a list of expressions for the gradient that can be evaluate at any point and a lists of lists of expressions for the Hessian that again can be evaluated to a constant matrix for any point.


Viewing all articles
Browse latest Browse all 23131

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>