Re: Shortening Polynomials
- To: mathgroup at christensen.cybernetics.net
- Subject: [mg424] Re: [mg413] Shortening Polynomials
- From: Count Dracula <lk3a at kelvin.seas.virginia.edu>
- Date: Tue, 24 Jan 1995 15:03:12 -0500
"Corcoran" == Stephen Corcoran <corcoran> writes:
Corcoran> Is there a neater way to collect powers up to order m after
Corcoran> expanding a polynomial?
Define a filtering function f (assuming poly has head Plus, which will be the case
for most applications):
f[poly_Plus, m_Integer, vars__Symbol] := Select[poly, Max[Exponent[#, {vars}]] <= m &]
Then, for example,
In[2]:= poly := Sum[a[i, j] x^i y^j, {i, 0, 4}, {j, 0, 4}]
In[3]:= f[poly, 2, x, y]
2 2 2 2 2 2
Out[3]= a[0, 0] + y a[0, 1] + y a[0, 2] + x a[1, 0] + x y a[1, 1] + x y a[1, 2] + x a[2, 0] + x y a[2, 1] + x y a[2, 2]
In[4]:= poly2 := Sum[x^i y^j z^k, {i, 0, 6}, {j, 0, 3}, {k, 0, 8}]
In[5]:= f[poly2, 2, x, y, z]
2 2 2 2 2 2 2 2 2 2 2 2 2
Out[5]= 1 + x + x + y + x y + x y + y + x y + x y + z + x z + x z + y z + x y z + x y z + y z + x y z + x y z + z +
2 2 2 2 2 2 2 2 2 2 2 2 2 2
x z + x z + y z + x y z + x y z + y z + x y z + x y z
In[6]:= poly3 := Sum[a[i] q^i, {i, 0, 9}];
In[7]:= f[poly3, 3, q]
2 3
Out[7]= a[0] + q a[1] + q a[2] + q a[3]
___________________________________________________________________________________
Levent Kitis lk3a at cars.mech.virginia.edu lk3a at kelvin.seas.virginia.edu
University of Virginia Department of Mechanical, Aerospace and Nuclear Engineering
___________________________________________________________________________________