On 11/1/12 7:08 AM, Jotace wrote:
Hi all,

How do I create a family of variables. I would need to create, say x_i
for i \in N, or at least to have the possibility to use variables x_i
for arbitrari i's

If it's too complex, it would be enough to create a fixed rannge of
variables, say x_i for i in range(100). What I need to do is to create a
famili of polynomials p_i, each of whicj is a polynomial in x_1, x_2,
x_{i+2}.

Here's a conversation about this:

https://groups.google.com/forum/?fromgroups=#!searchin/sage-support/Is$20there$20an$20efficient$20method$20of$20producing$20indexed$20variables?/sage-support/qj8q21wr7-0/Qs-Qxr8A0dAJ

In particular, this is a nice solution:

class SymbolicVariables(SageObject):
    def __init__(self, prefix='x'):
        self._prefix = prefix
    def __getitem__(self, i):
        return var("%s%s"%(self._prefix, i))


a = SymbolicVariables('a')
sum(a[i]*x^i for i in range(3))

would give a2*x^2 + a1*x + a0

Thanks,

Jason



--
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To post to this group, send email to sage-support@googlegroups.com.
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-support?hl=en.


Reply via email to