MatrixSymbol of real-valued variables

23 views
Skip to first unread message

Duy Nguyen Truong

unread,
Apr 19, 2015, 12:25:51 PM4/19/15
to sy...@googlegroups.com
Question: For Symbol, we can declare it as a real-valued variable: x = Symbol('x', real=True). Is there a way in sympy that we can declare a MatrixSymbol of dimension M * N whose elements are real-valued variables ?

Why: In the problem I am working on, I need to compute the differentiation of Abs of a matrix element (which is real-valued for my problem). However, the sympy output for matrix element is not as nice as the output of the differentiation of Abs of a real-value symbol. See the sample program:

>>> from sympy import *

>>> N = Symbol('N', integer=True)

>>> M = MatrixSymbol('M', N, N)

>>> diff(Abs(M[0,0]), M[0,0])

(re(M[0, 0])*Subs(Derivative(re(_xi_2), _xi_2), (_xi_2,), (M[0, 0],)) + im(M[0, 0])*Subs(Derivative(im(_xi_2), _xi_2), (_xi_2,), (M[0, 0],)))/Abs(M[0, 0])

>>> X = Symbol('X', real=True)

>>> diff(Abs(X), X)

sign(X)

Reply all
Reply to author
Forward
0 new messages