Tommy
Tommy

Reputation: 5

Matrix Multiplication Floats

I have a list of constants represented by alpha1, a1 .... theta4.

I can print correctly and read the individual matrices, however when i try matrix multiplication i receive error;

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

I believe it is something to do with multiplying floats.

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

Upvotes: 0

Views: 397

Answers (1)

Jérôme
Jérôme

Reputation: 14664

Your getTransformationMatrix function returns a list while you would like it to return a matrix.

I suspect you added those square brackets by mistake.

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

Try this:

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

Seeing this error

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

the first thing to do is to print no only T1, T2, etc. but also type(T1), etc.

You would see it is not what you expect.

Upvotes: 1

Related Questions