Ask Your Question
1

how to use variables in a matrix ?

asked 2017-11-07 11:40:07 +0200

Kamel gravatar image

Hello,

this code below doesn't do what I expect.

var('x'); M(x) = matrix(2, 2, [x,x,x,x]); M(3)

Can someone tell me what to do please ?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2017-11-07 13:47:56 +0200

tmonteil gravatar image

updated 2017-11-07 13:49:00 +0200

Well, you should perhaps tell what you would expect... Let me suggest two possibilities:

  • use a Python function:

    sage: M = lambda x : matrix(2, 2, [x,x,x,x])
    sage: M(3)
    [3 3]
    [3 3]
    
  • if you want to consider your matrix as a symbolic object:

    sage: var('x'); M = matrix(2, 2, [x,x,x,x])
    x
    sage: M
    [x x]
    [x x]
    sage: M.substitute(x=3)
    [3 3]
    [3 3]
    
edit flag offensive delete link more

Comments

ok, thanks.

Kamel gravatar imageKamel ( 2017-11-07 18:37:45 +0200 )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

Stats

Asked: 2017-11-07 11:40:07 +0200

Seen: 2,024 times

Last updated: Nov 07 '17