Relative Content

Tag Archive for sympydiffsymbolic-math

Why does Sympy’s diff function return a 4D array as an answer?

import sympy as sym from sympy import symbols x1,x2,x3 = symbols(‘x1,x2,x3’) X = sym.Matrix([[x1],[x2],[x3]]) print(X) A = sym.Matrix([[1,0,1], [0,1,1],[1,1,0]]) print(A) print(X.T*A*X) D = sym.diff(X.T*A*X , X) print(D.shape) print(D) print(D[0]) print(D[0][0]) print(D[0][0][0]) print(D[0][0][0][0]) The output of the above is as below: Matrix([[x1], [x2], [x3]]) Matrix([[1, 0, 1], [0, 1, 1], [1, 1, 0]]) Matrix([[x1*(x1 + x3) […]