({{, (RefLink[CoefficientArrays, paclet:ref/CoefficientArrays])[polys,vars]
gives the arrays of coefficients of the variables vars in the polynomials polys. }})

OpenersNotesSection(Spacer1)Details and Options

(RefLink[CoefficientArrays, paclet:ref/CoefficientArrays]) gives a list containing (RefLink[SparseArray, paclet:ref/SparseArray]) objects, which can be converted to ordinary arrays using (RefLink[Normal, paclet:ref/Normal]).

If (RefLink[CoefficientArrays, paclet:ref/CoefficientArrays])[polys,vars] gives {(Subscript[m, 0]),(Subscript[m, 1]),(Subscript[m, 2]),…}, then polys can be reconstructed as (Subscript[m, 0])+(Subscript[m, 1]).vars+(Subscript[m, 2]).vars.vars+…. »

Any element of polys of the form lhs==rhs is taken to correspond to the polynomial lhs-rhs. »

(RefLink[CoefficientArrays, paclet:ref/CoefficientArrays])[polys,{(Subscript[form, 1]),(Subscript[form, 2]),…}] takes all expressions in polys that match any of the (Subscript[form, i]) to be variables.

(RefLink[CoefficientArrays, paclet:ref/CoefficientArrays])[polys] is equivalent to (RefLink[CoefficientArrays, paclet:ref/CoefficientArrays])[polys,(RefLink[Variables, paclet:ref/Variables])[polys]].

The length of the list (RefLink[CoefficientArrays, paclet:ref/CoefficientArrays])[polys,vars] is one more than the total degree of polys.

The (Subscript[m, i]) are sparse arrays with ranks i+1.

The first element (Subscript[m, 0]) has the same length as the list polys.

If polys is a single polynomial rather than a list, (Subscript[m, 0]) is also not a list.

For linear equations, the solution to (RefLink[Thread, paclet:ref/Thread])[polys==0] is given by (RefLink[LinearSolve, paclet:ref/LinearSolve])[(Subscript[m, 1]),-(Subscript[m, 0])].

For nonlinear equations, the (Subscript[m, i]) are not unique. (RefLink[CoefficientArrays, paclet:ref/CoefficientArrays]) by default assigns nonzero coefficients only to monomials where the variables appear in the same order as vars.

(RefLink[CoefficientArrays, paclet:ref/CoefficientArrays])[polys,vars,"Symmetric"->(RefLink[True, paclet:ref/True])] makes all the (Subscript[m, i]) symmetric in all their indices. The resulting arrays will generally be less sparse.

OpenersPrimaryExamplesSection(Spacer1)Examples  (10)

OpenersExampleSection0(Spacer1)Basic Examples  (1)

CoefficientArrays[{a+x-y-z==0,b+x+2y+z==0},{x,y,z}]

Normal[%]

OpenersExampleSection1(Spacer1)Scope  (4)

Linear polynomial:

CoefficientArrays[2x+3y+4z+5,{x,y,z}]

Normal[%]

List of linear polynomials:

CoefficientArrays[{2x+3y+4z+5,6x+7y+8z+9},{x,y,z}]

Normal[%]

Nonlinear polynomials:

CoefficientArrays[{(x+y+1)^2,(x-y-2)^3},{x,y}]

Normal[%]

Polynomial equations:

CoefficientArrays[{c+x^2-z==0,x^2+2y+z^2==0},{x,y,z}]

Normal[%]

OpenersExampleSection2(Spacer1)Options  (1)

OpenersExampleSubsection0(Spacer1)"Symmetric"  (1)

The default coefficient of a quadratic form corresponding to y x is zero:

CoefficientArrays[a x^2+b x y+c y^2+d x+e y+f,{x,y}]//Normal

With "Symmetric"->(RefLink[True, paclet:ref/True]), (RefLink[CoefficientArrays, paclet:ref/CoefficientArrays]) gives symmetric arrays:

CoefficientArrays[a x^2+b x y+c y^2+d x+e y+f,{x,y},"Symmetric"->True]//Normal

OpenersExampleSection3(Spacer1)Applications  (1)

Convert linear equations to arrays suitable for (RefLink[LinearSolve, paclet:ref/LinearSolve]):

eqns={2x+3y+4z==5,9x+8y+7z==6,x+9y+2z==8};

{b,m}=CoefficientArrays[eqns,{x,y,z}]

LinearSolve[m,-b]

{x,y,z}/.Solve[eqns,{x,y,z}]

OpenersExampleSection4(Spacer1)Properties & Relations  (3)

The polynomial can be reconstructed by using (RefLink[Dot, paclet:ref/Dot]) (.):

v={x,y};

f=Expand[(2x+3y)^2+y^3]

c=CoefficientArrays[f,v]

c[[1]]+c[[2]].v+c[[3]].v.v+c[[4]].v.v.v//Expand

The symmetric coefficient arrays correspond to vector derivatives at the origin:

f=Expand[(2x+3y)^2+y^3]

CoefficientArrays[f,{x,y},"Symmetric"->True]//Normal

Table[D[f,{{x,y},n}]/n!,{n,0,3}]/.{x->0,y->0}

(RefLink[CoefficientArrays, paclet:ref/CoefficientArrays]) gives a list of arrays of polynomial coefficients ordered by total degrees:

f=(3x+5y)^4;

ca=CoefficientArrays[f,{x,y}]

(RefLink[CoefficientList, paclet:ref/CoefficientList]) gives a tensor of the coefficients:

cl=CoefficientList[f,{x, y}]

Use (RefLink[Coefficient, paclet:ref/Coefficient]) to find the coefficient of x(y^3):

Coefficient[f,x y^3]

In ca the position of this coefficient is a+b+1 followed by a 1s and b 2s (1 and 2 indicate the first and second variables):

ca[[5,1,2,2,2]]

In cl the coefficient of x^a y^b is the element at position {a+1,b+1}:

cl[[1+1,1+3]]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[CoefficientList, paclet:ref/CoefficientList])  ▪  (RefLink[CoefficientRules, paclet:ref/CoefficientRules])  ▪  (RefLink[Coefficient, paclet:ref/Coefficient])  ▪  (RefLink[SparseArray, paclet:ref/SparseArray])  ▪  (RefLink[Solve, paclet:ref/Solve])}})}})

({{DocumentationFooterIconsRelatedTutorial.png, ({{Tutorials}, {▪(RefLinkPlain[Sparse Arrays: Linear Algebra, paclet:tutorial/SparseArrays-LinearAlgebra])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Constructing Matrices, paclet:guide/ConstructingMatrices])}, {▪(RefLinkPlain[Sparse Arrays, paclet:guide/SparseArrays])}, {▪(RefLinkPlain[Manipulating Equations, paclet:guide/ManipulatingEquations])}, {▪(RefLinkPlain[Constructing Lists, paclet:guide/ConstructingLists])}, {▪(RefLinkPlain[Polynomial Systems, paclet:guide/PolynomialSystems])}, {▪(RefLinkPlain[Matrices and Linear Algebra, paclet:guide/MatricesAndLinearAlgebra])}})}})