2014-10-30 37 views
0

矩阵的符号我试图指数矩阵在这样指数sympy

from sympy import * 
vx1,vx2,vx3,vx4,vx5, vy1,vy2,vy3,vy4,vy5, = symbols('vx1 vx2 vx3 vx4 vx5 vy1 vy2 vy3 vy4 vy5') 
vx=Matrix([vx1,vx2,vx3,vx4,vx5]) 
vy=Matrix([vy1,vy2,vy3,vy4,vy5]) 
p, n = symbols('p n', integer=True) 
vx[0] 
vx[1] 
vx[2] 
vx[3] 
summation(p, (p, 0, 4)) 
summation(vx[p], (p, 0, 4)) 

求和但好像sympy不能做到这一点:

NameError: IndexError: Invalid index a[p] 

有没有办法?

回答

0

以下情况如何?

>>> sum(vx[p] for p in range(5)) 
vx1 + vx2 + vx3 + vx4 + vx5 
+0

也http://stackoverflow.com/questions/24834447/how-to-create-an-indexed-看variable-in-sympy和http://stackoverflow.com/questions/26402387/sympy-summation-with-indexed-variable – smichr 2014-10-30 14:49:49

3

如果你想有一个象征性的指数为一个矩阵,使用MatrixSymbol:

In [15]: vx = MatrixSymbol('vx', 1, 4) 

In [16]: summation(vx[(0, p)], (p, 0, 4)).doit() 
Out[16]: vx₀₀ + vx₀₁ + vx₀₂ + vx₀₃ + vx₀₄