Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Hello, @chris233! I had the same problem some time ago. Check this related questions:

  1. https://ask.sagemath.org/question/47672/is-this-a-bug-or-intended-behavior/ (my related question, with an excellent answer by @rburing, with a list of additional cases where this particular syntax for function definition fails.)
  2. https://ask.sagemath.org/question/10457/arithmetic-with-matrices-of-formal-functions/ (this one has an excellent to-the-point explanation of this problem by @nbruin; this should answer your doubt.)

The only way around this problem (as far as I know) is to use pure Python syntax for function definition (In this case, "function" in the sense of computer pŕogramming, as a synonym of "subroutine", not "function" in the mathematical sense):

def f(x):
    return x * matrix([[5]])

(In my humble opinion, this is very unfortunate because mathematical function definition, like the one you intended, is a very convenient feature.)

I hope this helps!