Zoho, On Mon, Jan 07, 2008 at 10:13:34AM -0800, Zoho wrote: > > Hello: > > I am brand new to python/sympy scripting and I have a project I have > written in Maxima but would like to port it to sympy (as it is far > more readable than the specific Maxima language) but I am not sure if > sympy yet has the funcialanity that I require. > > What I would like to do is create an array with symbolic coefficients > and then use the array coeffiecents to create expressions. The > coeffiecents are solved for later. To give you and idea of what I mean > here is a small snippet of the Maxima code: > > /* A Maxima program to solve > psi'' + lambda *sin(psi) = 0 , psi'(0)=psi'(1)=0, > int(sin(psi(s),s=0..1) = 0. > where psi = b*cos(n*pi*s) + b^3*cos^3(n*pi*s) + ... > lambda=1+k*b^2+k*b^4 + ... */ > > /* Setup the expressions for psi, lambda, x, y and solve for > the parameters */ > setup(terms):=block([], > kill(k,a,b,d), > n:terms, > ratweight (b,1,c,1), > ratwtlvl: 2*(2*n+1), > /* Calculate expansion for psi and lambda */ > C[0]:c, > Cpp[0]:-c, > k[0]:1, > for i thru n do ( > C[i]:sum(a[i,j]*c^(2*j+1),j,1,i), > > Cpp[i]:sum(a[i,j]*(-(2*j+1)^2*c^(2*j+1)+(2*j+1)*(2*j)*c^(2*j-1)),j, > 1,i) ), > psi:sum(b^(2*i+1)*C[i], i,0,n), > lam:sum(b^(2*i)*k[i], i,0,n), > > .... > > in the Maxima code you do not need to declare the array before. Here > 'a' is an array and the expressions 'psi' and 'lam' are later solved > for the coefficients. > > So is there a way to do this using sympy?
Is this what you need? ======================================== #!/usr/bin/env python from sympy import * pprint_try_use_unicode() c = Symbol('c') b = Symbol('b') def irange(a,b): """inclusive range -- range(a,b+1)""" return range(a,b+1) def setup_terms(n): a = {} C = [None]*(n+1) C[0] = c for i in irange(1,n): for j in irange(1,i): a[i,j] = Symbol('a_%i%i' % (i,j)) C[i] = sum(a[i,j] * c**(2*j+1) for j in irange(1,i)) psi = sum(b**(2*i+1) * C[i] for i in irange(0,n)) return psi if __name__ == '__main__': psi = setup_terms(3) print 'PSI:' pprint(psi) ======================================== On my host the output is: [EMAIL PROTECTED]:~/src/sympy/sympy$ ./psi.py PSI: 5 ⎛ 3 5⎞ 7 ⎛ 3 5 7⎞ 3 3 b*c + b *⎝a₂₁*c + a₂₂*c ⎠ + b *⎝a₃₁*c + a₃₂*c + a₃₃*c ⎠ + a₁₁*b *c > post scriptum: Thank you for writing such great software! Thanks for your interest to SymPy too! -- Всего хорошего, Кирилл. http://landau.phys.spbu.ru/~kirr/aiv/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sympy" group. To post to this group, send email to sympy@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sympy?hl=en -~----------~----~----~----~------~----~------~--~---