If I have a polynomial, say $p(x) = 6x^3 - x^2 + x$, and I want to express that in terms of a sum of other polynomials how may I do that in Mathematica? Specifically I would like to say that $$p(x) = \sum_{i = 0}^3 \alpha_iL_i(x)$$ where $L_i(x)$ is the $i^{th}$ Legendre Polynomial (not super important what exactly the other polynomial is).

I have attempted the following:

p = 6*x^3 - x^2 + x;
Solve[p == (C3*LegendreP[3, x] + C2*LegendreP[2, x] + 
  C1*LegendreP[1, x] + C0*LegendreP[0, x]), {C3, C2, C1, C0}]

but it gives

 {{C0 -> x - C1 x - x^2 + 6 x^3 - 1/2 C2 (-1 + 3 x^2) - 
    1/2 C3 (-3 x + 5 x^3)}}

as the output when I know (for this example) the C's are real numbers.


Please see if this does what you want. If not, will delete this answer.

p      = 6*x^3 - x^2 + x;
coeff  = CoefficientList[p, x]
p0     = Expand[C3*LegendreP[3, x] + C2*LegendreP[2, x] + C1*LegendreP[1, x] + 
              C0*LegendreP[0, x]];

Mathematica graphics

coeff0 = CoefficientList[p0, x];
eqs    = Thread[coeff == coeff0];

Mathematica graphics

sol = First@Solve[eqs, {C0, C1, C2, C3}]

Mathematica graphics

To verify

 p0 /. sol

Mathematica graphics

  • 1
    $\begingroup$ @C.Fuhrman - You have four unknowns so Solve needs four equations to determine them. As shown by @Nasser, the four equations are obtained by equating the corresponding coefficients. $\endgroup$ – Bob Hanlon Sep 30 at 15:21

Here's a different method using SolveAlways:

poly = 6 x^3 - x^2 + x
SolveAlways[poly == Sum[C[i] LegendreP[i, x], {i, 0, 3}], x]

{{C[0] -> -(1/3), C[2] -> -(2/3), C[1] -> 23/5, C[3] -> 12/5}}


This is the job of PolynomialReduce; see the documentation here.

For your example,

PolynomialReduce[p, Table[LegendreP[i, x], {i, 0, 3}], {x}]

is the idiomatic way. The output is of the form {coefficientList, remainder} where in the cases where the reduction is possible, remainder is zero.

  • $\begingroup$ This won't work though, because the multipliers can be (and are, in this case) polynomials in 'x'. One can homogenize everything to degree 3 however; that seems to work. Multiplying each degree in x by a distinct new variable is another way to go about this. $\endgroup$ – Daniel Lichtblau Oct 2 at 16:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.