Currently symbolic variables are un-indexable. What would people  
think of having indexing create new subscripted variables?

sage: a = var('a')
sage: a[0]
a_0
sage: latex(a[1,2])
a_{1,2}

- Robert


On Jun 3, 2009, at 10:32 AM, David Joyner wrote:

>
> I'm not sure if this helps, but you can create a polynomial
> of the type you want a bit simpler:
>
> sage: var("x,y")
> (x, y)
> sage: Inds = CartesianProduct(range(5), range(4))
> sage: sum([var("a"+str(i)+str(j))*x^i*y^j for i,j in Inds])
> a43*x^4*y^3 + a33*x^3*y^3 + a42*x^4*y^2 + a23*x^2*y^3 + a32*x^3*y^2 +
> a41*x^4*y + a13*x*y^3 + a22*x^2*y^2 + a31*x^3*y + a40*x^4 + a03*y^3 +
> a12*x*y^2 + a21*x^2*y + a30*x^3 + a02*y^2 + a11*x*y + a20*x^2 + a01*y
> + a10*x + a00
>
> Now you can reference them on the fly like this:
>
> sage: eval("a"+str(3)+str(2))
> a32
>
> On Wed, Jun 3, 2009 at 10:51 AM, James Parson <par...@hood.edu> wrote:
>>
>> Dear sage-support group,
>>
>> I am completely new to computer algebra systems and to computer
>> programming, and I hope you'll indulge the following beginner's
>> question. I was wondering if there is a simple way to create a
>> polynomial of degree d in x and y with symbolic coefficients in Sage.
>> Here is what I mean: if I were at the board in class, I might write
>> (in LaTeX transcription) something like
>>
>> P(x,y) = \sum_{i+j\leq d} a_{ij} x^i y^j,
>>
>> which I would view as an element of \mathbf{Z}[a_{ij},x,y]. I might
>> then impose some linear conditions on the a_{ij} by insisting that P
>> (x_t,y_t) = 0 for a list of points
>>
>> (x_1,y_1), (x_2,y_2), ... .
>>
>> Finally, I might solve the resulting system of linear equations.
>>
>> How would you recommend that I set up something like the a_{ij} and P
>> (x,y) in Sage? In order to make the question more definite, I
>> illustrate it with an example that I took from a lecture of Doron
>> Zeilberger on experimental mathematics. He proposed the question of
>> finding a polynomial of degree d in x and y that vanishes when x  
>> and y
>> are specialized to consecutive Fibonacci numbers. The lines below are
>> my attempt at a Sage version of his suggested computer search for a
>> likely solution (originally written in Maple). The program should  
>> take
>> the degree d as an input and then provide a parameterized family of
>> polynomials of degree d that are likely candidates.
>>
>> Here is what I came up with, after an enlightening afternoon of
>> studying computer manuals:
>>
>> d = 4
>> e = d+1
>> L = []
>> M = []
>> for i in range(e):
>>    for j in range(e-i):
>>      L.append('a_%s_%s' %(i,j))
>>      M.append([i,j])
>> V = var(' '.join(L))
>> P = sum(V[j]*x^(M[j][0])*y^(M[j][1]) for j in range(len(L)))
>> E = [P(x=fibonacci(n),y=fibonacci(n+1)) for n in range(1,len(V)+6)]
>> P.substitute(solve(E,V,solution_dict = True)[0])
>>
>> I could not figure out how to create and reference the variables a_
>> {ij} conveniently, and so I ended up with the strange lists V and M
>> above. Even though I got my polynomial P and solved the original
>> problem to my satisfaction, I still don't think I know how I would
>> have Sage do something like sum the a_{i.i+1} for 2i+1<=d. Is there a
>> better way to do this sort of thing?
>>
>>
>> Thanks for your help and indulgence,
>>
>> James Parson
>>
>>>
>>
>
> >


--~--~---------~--~----~------------~-------~--~----~
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
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to