Re: coefficient of a polynomial term
- To: mathgroup at smc.vnet.net
- Subject: [mg59360] Re: [mg59339] coefficient of a polynomial term
- From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
- Date: Sun, 7 Aug 2005 03:46:55 -0400 (EDT)
- References: <200508060529.BAA01135@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
On 6 Aug 2005, at 07:29, Tun Myint Aung wrote: > Dear Mathgroup, > > One more question again! How to extract the coefficient of a > polynomial term. For example: > > poly = 2 x^2 +3 x*y +4 y^2+x^3 > > I would like to get 2 for first term, 3 for second term, 4 for > third term and so on.. > > Thank everyone for answering my questions > > > With Regards, > > Tun Myint Aung > > 0ne way is to use the built in function CoefficientList: poly = 2 x^2 +3 x*y +4 y^2+x^3; ls = CoefficientList[poly, {x, y}] {{0, 0, 4}, {0, 3, 0}, {2, 0, 0}, {1, 0, 0}} This returns an array, where the coefficient of x^i y^j is the entry ls[[i+1,j+1]], for example the coefficient of y^2 is ls[[1,3]] 4 There are also undocumented algebra functions whose output contains the coefficients of a polynomial, for example s=Internal`DistributedTermsList[poly,{x,y}] {{{{3, 0}, 1}, {{2, 0}, 2}, {{1, 1}, 3}, {{0, 2}, 4}}, {x, y}} You can extract the coefficients with, for example: s[[1,All,1]][[All,1]] {3,2,1,0} Andrzej Kozlowski
- References:
- coefficient of a polynomial term
- From: "Tun Myint Aung" <tma@nus.edu.sg>
- coefficient of a polynomial term