2016-04-07 21 views
0

alpha1, a1 .... theta4 tarafından temsil edilen sabitlerin bir listesini aldım.Matris Çarpma Yüzenleri

Doğru yazdırabilir ve tek tek matrisleri okuyabilirim, ancak matris çarpmasını denediğimde hata alıyorum;

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

Yüzen çarpanlarla ilgili bir şey olduğuna inanıyorum. Eğer bir matris dönmek için istemekle birlikte

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 

cevap

1

Sizin getTransformationMatrix işlev bir listesini döndürür.

Bu köşeli parantezleri yanlışlıkla eklediğinizden şüpheleniyorum.

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]; 

bu deneyin:

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 

bu hatayı

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

Yapılacak ilk şey görünce hayır sadece T1, T2 vb aynı zamanda type(T1) vb

yazdırmaktır

Beklediğiniz gibi değil.

+0

Mükemmel Teşekkür ederim! ve tip() ipucu için teşekkür ederiz! – Tommy

+0

Yardım ettim sevindim. SO'ya hoşgeldiniz. –