Ask Your Question

Matrix Multiplication

asked 2010-12-28 11:15:18 -0500

mhfrey gravatar image

updated 2010-12-28 11:40:58 -0500

Mike Hansen gravatar image

I am trying to multiply the following:


This should work, what am I doing wrong? I would expect (1/2, 0)

Sage returns the following error:

Traceback (click to the left of this block for traceback)
TypeError: 'sage.matrix.matrix_rational_dense.Matrix_rational_dense'
object cannot be interpreted as an index

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "", line 10, in <module>
    exec compile(u'open("","w").write("# -*- coding: utf-8 -*-\\n" +    _support_.preparse_worksheet_cell(base64.b64decode("SXo9MS8yKm1hdHJpeCgyLDIsW1sxLDBdLFswLC0xXV0pO0l6CmE9KDEsMCkKSXoqYQ=="),globals())+"\\n"); execfile(os.path.abspath(""))
  File "", line 1, in <module>

  File "/tmp/tmpJoBb2Y/", line 5, in <module>
    exec compile(u'Iz*a
  File "", line 1, in <module>

  File "element.pyx", line 2260, in sage.structure.element.Matrix.__mul__     (sage/structure/element.c:14881)
  File "coerce.pyx", line 759, in sage.structure.coerce.CoercionModel_cache_maps.bin_op (sage/structure/coerce.c:6940)
TypeError: 'sage.matrix.matrix_rational_dense.Matrix_rational_dense' object cannot be interpreted as an index


edit retag flag offensive close merge delete

2 answers

Sort by » oldest newest most voted

answered 2010-12-28 11:44:37 -0500

Mike Hansen gravatar image

The issue is that when you do a = (1,0) you are creating a tuple which is one of Python's built-in data types.

sage: type((1,0))
<type 'tuple'>

Sage doesn't "know" how to multiply a matrix and a tuple.

If you make a a vector instead, then thing will work like you want:

sage: Iz=1/2*matrix(2,2,[[1,0],[0,-1]])
sage: a = vector([1,0])
sage: type(a)
<type 'sage.modules.vector_rational_dense.Vector_rational_dense'>
sage: Iz * a
(1/2, 0)
edit flag offensive delete link more

answered 2010-12-28 13:35:54 -0500

mhfrey gravatar image

That works, thank you for the quick answer.

edit flag offensive delete link more


If you want to, you can accept Mike's answer, so that other users know this question was answered correctly when they search for a similar problem!

kcrisman gravatar imagekcrisman ( 2011-01-03 15:03:09 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2010-12-28 11:15:18 -0500

Seen: 1,192 times

Last updated: Dec 28 '10