Ask Your Question
2

matrix_plot not returning any outputs in subroutines

asked 2021-04-15 22:56:30 +0200

user2021 gravatar image
 A=identity_matrix(2)
    def f(n):
        matrix_plot(n*A)
    f(5)

I'm puzzled as the command matrix_plot(5*A) works fine on itself, but it produces no output when it goes inside a subroutine as in the above SageMath code.

I'd appreciate any help with understanding why this is so/resolving this.

PS I have tested this both on http://Sagecell.sagemath.org and a local installation.

edit retag flag offensive close merge delete

Comments

slelievre gravatar imageslelievre ( 2021-04-17 01:03:41 +0200 )edit

1 Answer

Sort by » oldest newest most voted
3

answered 2021-04-16 19:29:20 +0200

rburing gravatar image

The reason is the following: the notebook and command line interface, when they are evaluating input, at the end they always output the value of the last line in the input, if it is not None.

So indeed, if you enter matrix_plot(5*A) directly, you get your plot because it is the value of that line.

When you enter f(5), the body of the function is executed as it should be, but this function body does not explicitly return any value, so the default value None is returned, which results in no output.

You probably meant to write:

def f(n):
    return matrix_plot(n*A)

or equivalently

f = lambda n: matrix_plot(n*A)
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

1 follower

Stats

Asked: 2021-04-15 22:56:30 +0200

Seen: 29 times

Last updated: Apr 16