2016-04-07 22 views
0

私はalpha1、a1 .... theta4で表される定数のリストを持っています。行列乗算フロート

私は正しく印刷し、個々の行列を読むことができますが、行列の乗算を試みるとエラーが発生します。

print T1 * T2 * T3 * T4 
TypeError: can't multiply sequence by non-int of type 'list' 

私はフロートの乗算と関係があると信じています。

from numpy import matrix 
import math 

def getTransformationMatrix(alpha, a, d, theta): 
    transformationMatrix = matrix([[math.cos(theta),math.cos(alpha)*math.sin(theta),math.sin(alpha)*math.sin(theta) ,a*math.cos(theta)], [math.sin(theta),math.cos(alpha)*math.sin(alpha) ,-math.sin(alpha)*math.cos(theta),a*math.sin(theta)],[0,math.sin(alpha),math.cos(alpha),d],[0,0,0,1]]) 
    return[transformationMatrix]; 

T1 = getTransformationMatrix(alpha1, a1, d1, theta1) 
T2 = getTransformationMatrix(alpha2, a2, d2, theta2) 
T3 = getTransformationMatrix(alpha3, a3, d3, theta3) 
T4 = getTransformationMatrix(alpha4, a4, d4, theta4) 

print T1 * T2 * T3 * T4 

答えて

1

getTransformationMatrix関数は、行列を返す間にリストを返します。

誤って角括弧を追加したと思われます。

def getTransformationMatrix(alpha, a, d, theta): 
    transformationMatrix = matrix([[math.cos(theta),math.cos(alpha)*math.sin(theta),math.sin(alpha)*math.sin(theta) ,a*math.cos(theta)], [math.sin(theta),math.cos(alpha)*math.sin(alpha) ,-math.sin(alpha)*math.cos(theta),a*math.sin(theta)],[0,math.sin(alpha),math.cos(alpha),d],[0,0,0,1]]) 
    return [transformationMatrix]; 

これを試してみてください:

def getTransformationMatrix(alpha, a, d, theta): 
    transformationMatrix = matrix([[math.cos(theta),math.cos(alpha)*math.sin(theta),math.sin(alpha)*math.sin(theta) ,a*math.cos(theta)], [math.sin(theta),math.cos(alpha)*math.sin(alpha) ,-math.sin(alpha)*math.cos(theta),a*math.sin(theta)],[0,math.sin(alpha),math.cos(alpha),d],[0,0,0,1]]) 
    return transformationMatrix 

等、最初に行うべきこと等、いかなるのみT1T2を印刷しないことです。このエラーに

TypeError: can't multiply sequence by non-int of type 'list' 

を見てもtype(T1)

あなたはそれがあなたが期待するものではないことが分かります。

+0

ありがとうございます! ()チップの方がよかった! – Tommy

+0

喜んで助けました。ようこそ。 –