<s>[INST] How to express $2x^3-x^2-3x+2$ as a linear combination of Legendre polynomials I have used the formula
\begin{align}p_0(x)&=1\\
p_1(x)&=x\\
p_2(x)&=\frac12(3x^2−1)\\
p_3(x)&=\frac12(5x^3−3x)
\end{align}
$$2x^3-x^2-3x+2=Ap_3(x)+Bp_2(x)+Cp_1(x)+Dp_0(x)$$
EDIT-
\begin{align}&=\frac A2(5x^3−3x) + \frac B2(3x^2−1) + Cx +D \end{align}
but don't know how to continue after this.
 [/INST] In matrix form,
$$\begin{bmatrix} p_0\\ p_1\\ p_2\\ p_3\end{bmatrix} = \begin{bmatrix} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0\\ -\frac{1}{2} & 0 & \frac{3}{2} & 0\\ 0 & -\frac{3}{2} & 0 & \frac{5}{2}\end{bmatrix} \begin{bmatrix} 1\\ x\\ x^2\\ x^3\end{bmatrix}$$
We want to find a weight vector $\mathrm{w}$ such that
$$2 x^3 - x^2 - 3 x + 2 = \begin{bmatrix} w_0\\ w_1\\ w_2\\ w_3\end{bmatrix}^T \begin{bmatrix} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0\\ -\frac{1}{2} & 0 & \frac{3}{2} & 0\\ 0 & -\frac{3}{2} & 0 & \frac{5}{2}\end{bmatrix} \begin{bmatrix} 1\\ x\\ x^2\\ x^3\end{bmatrix}$$
and, thus, we have to solve the linear system
$$\begin{bmatrix} 2\\ -3\\ -1\\ 2\end{bmatrix}^T = \begin{bmatrix} w_0\\ w_1\\ w_2\\ w_3\end{bmatrix}^T \begin{bmatrix} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0\\ -\frac{1}{2} & 0 & \frac{3}{2} & 0\\ 0 & -\frac{3}{2} & 0 & \frac{5}{2}\end{bmatrix}$$
or, in a more standard form,
$$\begin{bmatrix} 1 & 0 & -\frac{1}{2} & 0\\ 0 & 1 & 0 & -\frac{3}{2}\\ 0 & 0 & \frac{3}{2} & 0\\ 0 & 0 & 0 & \frac{5}{2}\end{bmatrix} \begin{bmatrix} w_0\\ w_1\\ w_2\\ w_3\end{bmatrix} = \begin{bmatrix} 2\\ -3\\ -1\\ 2\end{bmatrix}$$
The solution is
$$\frac{5}{3} \, p_0 (x) - \frac{9}{5} \, p_1 (x) - \frac{2}{3} \, p_2 (x) + \frac{4}{5} \, p_3 (x) = 2 x^3 - x^2 - 3 x + 2$$
</s>