1

I am learning Sympy to know the Symbolic operations in Python. I want to find out the derivative of a matrix.

example matrix

How could I derivate the matrix in respect to b.

import sympy as sp
B = sp.Matrix([[(a*c),(b**2)],[(b*d),(d*a)]])
B

This can not help me to give my answer.

Saswati
  • 43
  • 5

1 Answers1

1

Assuming you want the usual matrix-by-scalar derivative and that you're using sympy 1.7, then the following should work:

import sympy as sp
a, b, c, d = sp.symbols("a b c d")
B = sp.Matrix([[(a*c),(b**2)],[(b*d),(d*a)]])
B.diff(b)

Returns:

Matrix([
[0, 2*b],
[d,   0]])

Which seems right to me. More here.

kabdulla
  • 5,199
  • 3
  • 17
  • 30