Transformation Matrix representing $D: P_2 \to P_2$ with respect to the basis $B$. 
Let $P_2 =\lbrace a_0 +a_1t+a_2t^2:a_0,a_1,a_2 \in R \rbrace$ be the set of polynomials of degree $2$ or less. The linear mapping $D:P_2\to P_2$ is such that $$D(p(t)) = \frac{d}{dt} (t \cdot p(t))$$for $p(t) \in P_2$.
a. Show that $B = \lbrace 1, \space 1+t, \space 1+ t + t^2 \rbrace$ is a basis for $P_2$
b. Find the transformation matrix representing $D$ with respect to the basis $B$.

This is a question from last year's final examination..I have already shown that $B$ is a basis for $P_2$, but I actually have no clue how to do the second part. I have compiled my answer based on what I have seen done in similar questions, but I am not sure if it makes any sense or if I am way off the mark? As a result, I am not really sure of the logic behind it either.
My attempt:
First we have to find $D(1), \space D(1+t), \space D(1+t+t^2)$
$$D(1) = \frac{d}{dt} t=1$$ 
$$D(1+t) =\frac{d}{dt}(t+t^2)=1+2t$$ 
$$D(1+t+t^2) =\frac{d}{dt} (t+t^2+t^3) = 1+2t+3t^2$$
Then we have to express in terms of the basis vectors of the range which is $\lbrace 1, \space 1+t, \space 1+ t + t^2 \rbrace$. So now :
$$D(1) = 1 \implies 1 + 0 \cdot (1+t) + 0 \cdot (1+t+t^2) \therefore (1,\space0,\space0)$$
$\space$
$$D(1+t) = 1+ 2t = a(1) + b(1+t) + c(1+t+t^2)$$
$$= 1+2t = (a + b + c) + (b + c)t + ct^2$$
$$a + b+ c =1, \space b+c = 2$$
$$c =0, \space b=2, \space a = -1$$
$$1+2t = -1(1) + 2(1+t) + 0(1+t+t^2) \implies -1 + 2(1+t)$$
$$\therefore (-1,\space2,\space0)$$
$\space$
$$D(1+t+t^2)=1+2t+3t^2 = a(1)+b(1+t)+c(1+t+t^2)$$ 
$$=1+2t+3t^2= (a + b + c) + (b + c)t + ct^2$$
$$a+b+c = 1, \space b+c =2$$
$$c=3, \space b=-1, \space a=-1$$
$$1+2t+3t^2 = -1(1)+(-1)(1+t)+3(1+t+t^2) \implies -1 -(1+t) + 3(1+t+t^2)$$
$$\therefore (-1,\space-1,\space3)$$
$\space$
And finally, the transformation matrix representing $D$ with respect to the basis $B$ would be the transpose of the each vector, which would give:
$$
        \begin{pmatrix}
        1 & -1 & -1 \\
        0 & 2 & -1 \\
        0 & 0 & 3 \\
        \end{pmatrix}
$$
 A: Let $[D]$ denote the matrix representation of the operator $T$ with respect to the given basis $B$ (in both the domain and range space of $D$). Let $[v]_B$ denote the coordinates of the vector $v$ in the basis $B$. If $[D]$ is the matrix of $D$ (with respect to $B$), then that means
$$
D([v]_B)=[D][v]_B.
$$
That is, we want to find $[D]_B$ such that
$$
D\left(\begin{bmatrix} a\\b\\c\end{bmatrix}_B\right)=[D]\begin{bmatrix} a\\b\\c\end{bmatrix}_B.
$$
Expanding the left-hand side based on the definition of $D$,
\begin{align}
D\left(\begin{bmatrix} a\\b\\c\end{bmatrix}_B\right)&={d\over dt}(t\cdot (a\cdot 1+b\cdot(1+t)+c\cdot(1+t+t^2)))\\
&={d\over dt}((a+b+c)t+(b+c)t^2+ct^3)\\
&=a+b+c+2(b+c)t+3ct^2.
\end{align}
So we want to rewrite the last line above in terms of a matrix multiple of $\begin{bmatrix} a\\b\\c\end{bmatrix}_B$. That is, find $k_1,k_2,k_3$ such that
$$
a+b+c+2(b+c)t+3ct^2=k_1\cdot 1+k_2(1+t)+k_3(1+t+t^2).
$$
Equating like terms, we get
\begin{align}
a+b+c&=k_1+k_2+k_3\\
2b+2c&=k_2+k_3\\
3c&=k_3,
\end{align}
which has solution
\begin{align}
k_1&=a-b-c\\
k_2&=2b-c\\
k_3&=3c.
\end{align}
Thus, we now see how the operator $D$ acts on input vectors (in $B$ coordinates):
$$
\begin{bmatrix} a\\b\\c\end{bmatrix}_B\overset{D}{\longmapsto}\begin{bmatrix} a-b-c\\2b-c\\3c\end{bmatrix}_B. 
$$
Therefore, the matrix of the transformation $D$ (with respect to the $B$ basis) is 
$$
[D]_B=\begin{bmatrix} 1 & -1 & -1\\ 0 & 2 & -1\\ 0 & 0 & 3\end{bmatrix}
$$
since
$$
D\left(\begin{bmatrix} a\\b\\c\end{bmatrix}_B\right)=\begin{bmatrix} 1 & -1 & -1\\ 0 & 2 & -1\\ 0 & 0 & 3\end{bmatrix}\begin{bmatrix} a\\b\\c\end{bmatrix}_B=\begin{bmatrix} a-b-c\\2b-c\\3c\end{bmatrix}_B.
$$
