Re: polynomial operations through CoefficientList
- To: mathgroup at smc.vnet.net
- Subject: [mg44758] Re: polynomial operations through CoefficientList
- From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
- Date: Tue, 25 Nov 2003 00:45:27 -0500 (EST)
- Organization: Universitaet Leipzig
- References: <bps3jo$9pu$1@smc.vnet.net>
- Reply-to: kuska at informatik.uni-leipzig.de
- Sender: owner-wri-mathgroup at wolfram.com
Hi,
CoefficientAdd[lst1_, lst2_] /; Length[lst1] == Length[lst2] := lst1 +
lst2
CoefficientAdd[lst1_, lst2_] /; Length[lst1] > Length[lst2] :=
CoefficientAdd[lst1, PadRight[lst2, Length[lst1], 0]]
CoefficientAdd[lst1_, lst2_] := CoefficientAdd[lst2, lst1]
and
p1[x_] := 1 + k1 x - 2 k2 x^2
p2[x_] := -2 - k3 x
lst1 = CoefficientList[p1[x], x];
lst2 = CoefficientList[p2[x], x];
CoefficientAdd[lst1, lst2]
will help you.
Regards
Jens
Paolo Bientinesi wrote:
>
> Hello,
> does anybody have 2 functions ready to multiply and add
> 2 polynomials directly from their CoefficientList's?
>
> example: the polynomials I'm considering are
> p1[x_] := 1 + k1 x - 2 k2 x^2
> p2[x_] := -2 -k3 x
>
> Given
> cf1 = {1,k1,-2 k2}
> and
> cf2 = {-2,-k3}
>
> I would like to get the list
> {-2,-2 k1-k3,4 k2-k1 k3,2 k2 k3}
> for p1[x]*p2[x]
>
> and the list
> {-1,k1-k3,-2 k2}
> for p1[x]+p2[x]
>
> without performing operations like
>
> CoefficientList[
> cf1.Table[x^i,{i,0,Length[cf1]-1}]*
> cf2.Table[x^i,{i,0,Length[cf2]-1}], x]
>
> Thanks!
> --
> Paolo
>
> pauldj at cs.utexas.edu paolo.bientinesi at iit.cnr.it