Labels

Tuesday, August 25, 2020

Compute Jacobian matrix by Sympy

Computing the Jacobian matrix is not easy, but we can use the python symbolical package Sympy to get it.

Here is a simple example.

import sympy as sym
from sysmpy import init_printing
from sympy import sin,cos,Matrix

init_printing()

x,y=sym.symbols('x y')
F=Matrix([x*cos(y),x*sin(y),x**2])
X=Matrix([x,y])
print(F.jacobian(X))
print(F.jacbian(X).subs([(x,0),(y,1)]))



Reference:
https://docs.sympy.org/latest/modules/matrices/matrices.html
https://www.sympy.org/scipy-2017-codegen-tutorial/notebooks/20-ordinary-differential-equations.html

No comments:

Post a Comment