On Thu, Apr 1, 2010 at 10:50 PM, Minh Nguyen <nguyenmi...@gmail.com> wrote: > Hi, > > On Fri, Apr 2, 2010 at 12:36 PM, scott.h <scott.he...@gmail.com> wrote: > > <SNIP> > >> It seems like this should be simple but for the life of me I can't >> figure out how to do it. > > Here I'm taking a guess at what you really want to do. See the > following Sage session: > > [mv...@sage ~]$ sage > ---------------------------------------------------------------------- > | Sage Version 4.3.5, Release Date: 2010-03-28 | > | Type notebook() for the GUI, and license() for information. | > ---------------------------------------------------------------------- > sage: n = 3 > sage: M = random_matrix(ZZ, nrows=n); M > [ 2 2 -2] > [ 4 2 -7] > [ 2 -1 1] > sage: # create a list of unknown constants; these are actually > symbolic variables > sage: C = [var("C_%s" % i) for i in range(n)]; C > [C_0, C_1, C_2] > sage: X = [randint(1, 10) for i in range(n)]; X > [2, 3, 2] > sage: F = [C[i] * exp(M[i,i] * x) for i in range(n)]; F > [C_0*e^(2*x), C_1*e^(2*x), C_2*e^x] > sage: [F[i].substitute(x=X[i]) for i in range(n)] > [C_0*e^4, C_1*e^6, C_2*e^2]
It might be useful to have a constructor to simplify this. One would be able to do something like this: sage: a = SymbolicVariables('a') sage: sum(a[i]*x^i for i in range(3)) a2*x^2 + a1*x + a0 and Minh's session above would become: sage: n = 3 sage: M = random_matrix(ZZ, nrows=n) sage: c = SymbolicVariables('c') sage: [c[i] * exp(M[i,i] * x) for i in range(n)] [c0*e^(-x), c1*e^(-5*x), c2*e^(13*x)] Here is a very simple implementation of SymbolicVariables. class SymbolicVariables(SageObject): def __init__(self, prefix='x'): self._prefix = prefix def __getitem__(self, i): return var("%s%s"%(self._prefix, i)) Thoughts? Franco -- -- 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 For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org