First time here? Check out the FAQ!

Ask Your Question
0

define/generate new variables automatically

asked 11 years ago

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!

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
0

answered 11 years ago

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.

Preview: (hide)
link

Comments

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

gundamlh gravatar imagegundamlh ( 11 years ago )

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

gundamlh gravatar imagegundamlh ( 11 years ago )

`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 ( 11 years ago )

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: 11 years ago

Seen: 949 times

Last updated: Nov 22 '13