I am trying to evaluate the Jacobian at (x,y)=(0,0) but unable to do so.
import sympy as sp
from sympy import *
import numpy as np
x,y=sp.symbols('x,y', real=True)
J = Function('J')(x,y)
f1=-y
f2=x - 3*y*(1-x**2)
f1x=diff(f1,x)
f1y=diff(f1,y)
f2x=diff(f2,x)
f2y=diff(f2,y)
J=np.array([[f1x,f1y],[f2x,f2y]])
J1=J(0,0)
print J1
The error corresponding to
---> 16 J1=J(0,0)
is
TypeError: 'numpy.ndarray' object is not callable
The error you're getting is indeed because you're rebinding J
to a numpy array which is not a callable.
You should use the subs
method of sympy expressions to evaluate an expression in a point (as described in the basic operations documentation of Sympy):
J = sympy.Matrix([[f1x,f1y],[f2x,f2y]])
J.subs([(x,0), (y,0)])
Also, you might be interested in knowing that sympy offers a jacobian
method too:
>>> F = sympy.Matrix([f1,f2])
>>> F.jacobian([x,y])
Matrix([
[ 0, -1],
[6*x*y + 1, 3*x**2 - 3]])
>>> F.jacobian([x,y]).subs([(x,0), (y,0)])
Matrix([
[0, -1],
[1, -3]])