简体   繁体   中英

Trouble setting up matrix with sympy

I would like to do some symbolic mathe withe some matrices. But my code does not work. Setting up my first matrices is no problem but calculating the wanted one from the start matrices does not work and I do not know why. Any suggestions?

from sympy import *
from sympy import Matrix , pprint, symbols



niso=4

MM = Matrix(niso-1,1, lambda i,j:var('MM_%s' % (i+1) ))
MA = Matrix (niso-1,1, lambda i,j:var('m_%s%s' % ('A', chr(66+i)) ) )
MX = Matrix (niso-1,1, lambda i,j:var('m_%s%s'% (chr(66+i), 'A')))
Rb = Matrix(niso-1,1, lambda i,j:var('Rb_%s%d' % ( chr(65)+chr(66+i)+',', i+2)))
R = Matrix (niso, niso-1, lambda i,j: var('R_%s%d' % (chr(65+i)+',' , j+1 )))



A = Matrix(niso-1,niso-1, lambda i,j:var('A_%d' % i))

for i in range(0,niso-1):
        for j in range(0,niso-1):
            A[i,j]=Rb[i,0]*MM[i,0] + MM[i,0]

My code only leads to this error message.

TypeError: Can't multiply sequence by non-integer of type ''

The problem is that I thought that my matrices already contain only symbols so that multiplying should work.

I have solved by myselfe! The Rb constructor was indeed the problem! Changing it to

R = Matrix (niso, niso-1, lambda i,j: var('R_%s%d' % (chr(65+i) , j+2 )))

helped!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM