Ask Your Question

# define/generate new variables automatically

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 close merge delete

## 1 Answer

Sort by ยป oldest newest most voted

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.

more

## Comments

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

( 2013-11-22 09:43:35 +0200 )edit

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

( 2013-11-22 11:34:53 +0200 )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.

( 2013-11-23 09:33:49 +0200 )edit

## Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

## Stats

Asked: 2013-11-22 06:44:22 +0200

Seen: 652 times

Last updated: Nov 22 '13