Ask Your Question
1

Why doesn't f(alpha) act like a function?

asked 2018-12-23 16:58:12 +0200

deburgess7 gravatar image

updated 2023-01-09 23:59:49 +0200

tmonteil gravatar image

var('t,alpha,beta,gamma')

sage: i [ 0 -I] [-I 0]

sage: f(alpha) = cos(alpha)*i

sage: f(alpha) [ 0 -Icos(alpha)] [-Icos(alpha) 0]

sage: f(0) [ 0 -Icos(alpha)] [-Icos(alpha) 0]

edit retag flag offensive close merge delete

Comments

To display blocks of code or error messages, skip a line above and below, and do one of the following (all give the same result):

  • indent all code lines with 4 spaces
  • select all code lines and click the "code" button (the icon with '101 010')
  • select all code lines and hit ctrl-K

For instance, typing

If we define `f` by

    def f(x, y, z):
        return x * y * z

then `f(2, 3, 5)` returns `30` but `f(2*3*5)` gives:

    TypeError: f() takes exactly 3 arguments (1 given)

produces:

If we define f by

def f(x, y, z):
    return x * y * z

then f(2, 3, 5) returns 30 but f(2*3*5) gives:

TypeError: f() takes exactly 3 arguments (1 given)

Please edit your question to do that.

slelievre gravatar imageslelievre ( 2018-12-24 13:43:09 +0200 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2018-12-23 21:23:38 +0200

rburing gravatar image

updated 2018-12-23 21:30:44 +0200

This is trac ticket #12075 (since 2011).

This way to define a function is syntactic sugar offered by Sage, but it doesn't yet work for matrix functions.

I suggest defining an ordinary Python function instead (using a lambda for brevity):

sage: var('alpha')
sage: i = matrix(SR, [[ 0, -I], [-I, 0]])
sage: f = lambda x: cos(x)*i
sage: f(0)
[ 0 -I]
[-I  0]
sage: f(alpha)
[            0 -I*cos(alpha)]
[-I*cos(alpha)             0]
edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools

Stats

Asked: 2018-12-23 16:58:12 +0200

Seen: 234 times

Last updated: Dec 23 '18