Home > other >  how to get indexes of elements in MatrixSymbol
how to get indexes of elements in MatrixSymbol

Time:07-05

i generate two matrices :

y=MatrixSymbol('y', n, k)

T=MatrixSymbol('T', n,k) , where

n=k=3

then I get expressions :

  1. Matrix([[y[0, 2] 11.0 * y[1, 2] - 12.0 * y[2, 2] 195.0*exp(-100000/(5819.8 * T[1] 5819.8))*y[1, 1] * y[1, 2] 195.0 * exp(-100000/(5819.8 * T[1] 5819.8)) * y[1, 1]]])

and

  1. Matrix([[-y[1, 2] y[2, 2]]])

i would like to get for 1) a set of variables : { y[0,2] , y[1,2] , y[2,2] , T[1] , y[1,1] }

and for 2) set of variables : { y[1,2] , y[2,2] }

command results .free_symbols and .args do not suit me

CodePudding user response:

This is how you get those elements:

from sympy import *
from sympy.matrices.expressions.matexpr import MatrixElement

n=k=3
y=MatrixSymbol('y', n, k)
T=MatrixSymbol('T', n,k)

M1 = Matrix([[y[0, 2]   11.0 * y[1, 2] - 12.0 * y[2, 2]   195.0*exp(-100000/(5819.8 * T[1]   5819.8))*y[1, 1] * y[1, 2]   195.0 * exp(-100000/(5819.8 * T[1]   5819.8)) * y[1, 1]]])
M2 = Matrix([[-y[1, 2]   y[2, 2]]])

print(M1.atoms(MatrixElement))
# out: {y[0, 2], y[1, 1], T[0, 1], y[1, 2], y[2, 2]}
print(M2.atoms(MatrixElement))
# out: {y[1, 2], y[2, 2]}

CodePudding user response:

if I have

Matrix([[y[0, 1] 11.0 * y[1, 1] - 12.0 * y[2, 1] 26.0 * exp(-100000/(5819.8 * T[1] 5819.8)) * y[1, 0] * y[1, 2] 13.0 * exp(-100000/(5819.8 * T[1] 5819.8)) * y[1, 1] * y[1, 2] 156.0*exp(-100000/(5819.8 * T[1] 5819.8)) * y[1, 1]]])

then command .atoms(MatrixElement) gives an answer :

{y[1, 1], y[0, 1], y[2, 1]}

there should be an answer :

{y[0,1] , y[1,1] , y[2,1] , T[1] , y[1,0] , y[1,2]}

CodePudding user response:

here is my system of equations:

Matrix([[ T[0] - 0.142857142857143, T[0]   13.0 * T[1] - 14.0 * T[2] -         
          9566326530.61224 * exp(-100000/(5819.8 * T[1]   5819.8)) * y[1, 0] *                                           
          y[1, 2] - 19132653061.2245 * exp(-100000/(5819.8 * T[1]   5819.8)) * 
          y[1, 1] * y[1, 2] - 1530612244897.96 * exp(-100000/(5819.8 * T[1]   
          5819.8)) * y[1, 1], -T[1]   T[2], y[0, 0] - 1, y[0, 0]   11.0 * y[1,0] - 12.0 * y[2, 0] - 65.0 * exp(-100000/(5819.8 * T[1]   5819.8)) * y[1, 0] * y[1, 2]   195.0 * exp(-100000/(5819.8*T[1]   5819.8)) * y[1, 1], -y[1, 0]   y[2, 0], y[0, 1] - 1, y[0, 1]   11.0 * y[1, 1] - 12.0 * y[2, 1]   26.0 * exp(-100000/(5819.8 * T[1]   5819.8)) * y[1, 0] * y[1, 2]   13.0 * exp(-100000/(5819.8 * T[1]   5819.8)) * y[1, 1] * y[1, 2]   156.0 * exp(-100000/(5819.8 * T[1]   5819.8)) * y[1, 1], -y[1, 1]   y[2, 1], y[0, 2] - 1, y[0, 2]   11.0 * y[1, 2] - 12.0 * y[2, 2]   195.0*exp(-100000/(5819.8*T[1]   5819.8)) * y[1, 1] * y[1, 2]   195.0 * exp(-100000/(5819.8 * T[1]   5819.8)) * y[1, 1], -y[1, 2]   y[2, 2]]])
  • Related