| Author |
Comment/Response |
Eric Harley
|
10/12/05 08:25am
Well, I guess I answered my own question. I'm posting what I have come up with in case it's useful for anyone else.
I chose to use this approach (using the Exponent[] function) because it allows the resulting function to be much more flexible than I could figure out how to do with my own pattern matching. It can easily be used with specific variables, it includes stuff in the denominator of fractions, etc.
Clear[polyOrder];
polyOrder = Function[{poly, varlist, ord},
Block[{termsList, orderList, selTerms},
termsList = List @@ poly;
orderList = Exponent[#, varlist, List] & /@ termsList;
orderList = Map[Flatten, orderList, 2];
orderList = Apply[Plus, orderList, 2];
termsList = Transpose[{termsList, orderList}];
selTerms = Select[termsList, #〚2〛 ≤ ord &];
Plus @@ (#〚1〛 & /@ selTerms)
]
];
Note that poly isn't the direct result of the Series[] function in the question. You should do //Normal//Expand on it to get rid of the O[] terms and all the factoring.
varlist should always be in list form, like {x} or {x,y,z}.
ord is just a number, the order of the product of the variables in varlist for any given term.
URL: , |
|