Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

A list of symbolic variables

Hello, I'm new to sage so I hope that I'm asking a very basic question.

I'm trying to create a list of symbolic variables. I would like to be able to set the number of variables initially and then let sage create the list.

I was (sort of) able to achieve this when I realized that the input for var is a string, so I wrote the following, which produces six symbolic variables for me:

n=3;
for i in range(2*n):
      var('s_'+str(i))

In my context, the variables are actually real, and they satisfy a system of equations that I would also like sage to produce. By playing with strings, and then using eval on them so they became expressions, I was able to produce a few of the simpler equations, which sage can solve.

But when I run for loops indexed by i I can never seem to actually refer to the variables indexed by i. For example, the following will not make sense to sage:

for i in range(2*n):
        s_i = i

The only way I can think to achieve the above result is to create a string with a for loop that states the command I want, turn it into an expression, save it as an equation, and then include it in a big list of equations.

I have to do a lot more with these variables, so I hope someone can tell me what I am doing terribly wrong. The first thing I want to do is create a second list, w, defined as:

w_k = s_(2*n-k)

A list of symbolic variables

Hello, I'm new to sage so I hope that I'm asking a very basic question.

I'm trying to create a list of symbolic variables. I would like to be able to set the number of variables initially and then let sage create the list.

I was (sort of) able to achieve this when I realized that the input for var is a string, so I wrote the following, which produces six symbolic variables for me:

n=3;
for i in range(2*n):
      var('s_'+str(i))

In my context, the variables are actually real, and they satisfy a system of equations that I would also like sage to produce. By playing with strings, and then using eval on them so they became expressions, I was able to produce a few of the simpler equations, which sage can solve.

But when I run for loops indexed by i I can never seem to actually refer to the variables indexed by i. For example, the following will not make sense to sage:

for i in range(2*n):
        s_i = i

The only way I can think to achieve the above result is to create a string with a for loop that states the command I want, turn it into an expression, save it as an equation, and then include it in a big list of equations.equations. Even so, I can't index the equations by i either, so I can't create the 2*n equations that I would need...

I have to do a lot more with these variables, so I hope someone can tell me what I am doing terribly wrong. The first thing I want to do is create a second list, w, defined as:

w_k = s_(2*n-k)

A list of symbolic variables

Hello, I'm new to sage so I hope that I'm asking a very basic question.

I'm trying to create a list of symbolic variables. I would like to be able to set the number of variables initially and then let sage create the list.

I was (sort of) able to achieve this when I realized that the input for var is a string, so I wrote the following, which produces six symbolic variables for me:

n=3;
for i in range(2*n):
      var('s_'+str(i))

In my context, the variables are actually real, and they satisfy a system of equations that I would also like sage to produce. By playing with strings, and then using eval on them so they became expressions, I was able to produce a few of the simpler equations, which sage can solve.

But when I run for loops indexed by i I can never seem to actually refer to the variables indexed by i. For example, the following will not make sense to sage:

for i in range(2*n):
        s_i = i

The only way I can think to achieve the above result is to create a string with a for loop that states the command I want, turn it into an expression, save it as an equation, and then include it in a big list of equations. Even so, I can't index the equations by i either, so I can't create the 2*n equations that I would need...

I have to do a lot more with these variables, so I hope someone can tell me what I am doing terribly wrong. The first thing I want to do is create a second list, w, defined as:

w_k $w_k = s_(2*n-k)s_{2n-k}$