mirror of
https://github.com/janishutz/eth-summaries.git
synced 2026-03-14 17:00:05 +01:00
[NumCS] Add more sympy tricks
This commit is contained in:
14
semester3/numcs/parts/06_python/03_sympy-hessian.py
Normal file
14
semester3/numcs/parts/06_python/03_sympy-hessian.py
Normal file
@@ -0,0 +1,14 @@
|
||||
import sympy as sp
|
||||
|
||||
sym = sp.symbols("x, y")
|
||||
x, y = sym
|
||||
f = x**2 + y**2
|
||||
|
||||
# Compute gradient and hessian
|
||||
grad = [sp.diff(f, k) for k in sym]
|
||||
hess = [[sp.diff(f, k).diff(j) for j in sym] for k in sym]
|
||||
|
||||
# Compute jacobian of vector function
|
||||
x_m = sp.MatrixSymbol('x', 2, 1)
|
||||
two_d_func = sp.Matrix([[x_m[0]**2], [x_m[1]**2]])
|
||||
jacobi = two_d_func.jacobian(x_m)
|
||||
Reference in New Issue
Block a user