Ask Your Question
3

assign variable value

asked 2016-10-10 20:28:44 +0200

anonymous user

Anonymous

Hi!

I'm just getting started with Sage and therefore my question may sound really stupid (and nevertheless I couldn't find an answer here). I have a matrix with both symbolic entries and numerical values, let's say:

a,b=var('a,b')    
M=matrix([[1,a], [0,b]])

Now I want do assign a value to a:

a=0

However if I print M to the screen it still says a in the matrix and not 0.

You can clearly see that I'm really not used to Sage, so what's the problem here? What should I do if I want to assign a fixed value to a variable which is also used in the calculations where this variable appears?

Thank's for the answers, I know this will sound highly trivial for you!

Philipp

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2016-10-11 19:42:29 +0200

tmonteil gravatar image

You can just use substitution:

sage: M.substitute(a=0)
[1 0]
[0 b]
edit flag offensive delete link more

Comments

Thanks you!

philipp7 gravatar imagephilipp7 ( 2016-10-13 16:41:36 +0200 )edit
2

answered 2016-10-11 18:00:45 +0200

ndomes gravatar image

May be you can achieve what you want via an anonymous function.

a,b=var('a,b')    
M = lambda a,b : matrix([[1,a], [0,b]])
A = M(a,b)
show(A)
B = M(a=0,b=b)
show(B)
edit flag offensive delete link more

Comments

Thank you! Not such a nice intuitive solution as I hoped to get, I admit. However, this just seems to be quite different in Sage compared to e.g. Mathematica.

philipp7 gravatar imagephilipp7 ( 2016-10-13 16:40:46 +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

1 follower

Stats

Asked: 2016-10-10 20:28:44 +0200

Seen: 4,027 times

Last updated: Oct 11 '16