Ask Your Question
0

define/generate new variables automatically

asked 2013-11-22 06:44:22 +0100

gundamlh gravatar image

Dear all,

I'd like to use symbolic boxes in SAGE to check the proof of a theorem.

sage: var('a11, a12, a13, a21, a22, a23, a31, a32, a33');
sage: A = matrix(SR, 3, 3, [a11, a12, a13, a21, a22, a23, a31, a32, a33])

It is really time-consuming..

genvarname@MATLAB I can use this function with two/three for-loops to construct one symbolic matrix/tensor.

Thanks in advance!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2013-11-22 06:58:30 +0100

Luca gravatar image

Not exactly the same as genvarname, but there you go:

var(['a%d%d' % tuple(p) for p in Zmod(3)^2])

Of course, there's tons of other ways of obtaining a similar result.

edit flag offensive delete link more

Comments

wow, clever! Thanks! Does this "technique" appear quite often in codes in Numpy?

gundamlh gravatar imagegundamlh ( 2013-11-22 09:43:35 +0100 )edit

I know! What I should learn is NumPy.. http://mathesaurus.sourceforge.net/matlab-numpy.html, and ask questions in stackoverflow .

gundamlh gravatar imagegundamlh ( 2013-11-22 11:34:53 +0100 )edit

`Zmod` is a Sage object, so this technique is specific to Sage (`var` is specific to Sage, anyway). I guess in pure Python you'd write something like import itertools ['a%d%d' % p for p in itertools.product(range(3), range(3))] You can ask Sage related questions in stackoverflow too. Many of us watch the "sage" tag.

Luca gravatar imageLuca ( 2013-11-23 09:33:49 +0100 )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: 2013-11-22 06:44:22 +0100

Seen: 924 times

Last updated: Nov 22 '13