Let T be the matrix $T=\pmatrix{4&2\\1&5}$. The basis B is the vectors: $u_1=\pmatrix{1\\1}$ and $u_2=\pmatrix{1\\2}$. Write T with respect to the basis B.
What I've tried (which obviously didn't work) is to write the vectors $\pmatrix{4\\1}$ and $\pmatrix{2\\5}$ as linear combinations of the vectors in B. This is what I've normally would do to the change the basis of a vector. Why doesn't that work here? What am I misunderstanding?
Given any linear transformation $T$ and a basis $B$, the matrix representation of $T$ in the basis $B$ has the vectors $Tb$, expressed in the basis $B$, as columns. Here $b$ are the vectors of $B$.
In this case you are given the linear transformation through its matrix representation in the standard basis, but that doesn't really change anything.
If you want to think matrix arithmetic, and really understand what's going on from that angle, then in my opinion it really pays off to differ between the two concepts of, on one hand, vectors and linear transformations, and on the other hand, column vectors and matrices: A vector is a point in space, a linear transformation is a squishing, stretching or rotation of all points in that space. Column vectors and a matrices are organized collections of numbers we can use to do calculations. This will require some notation. (Fair warning: this notation is not in any way conventional.)
One important fact to take with you here is that $B_Av_B = v_A$, or equivalently, that $v_B = B_A^{-1}v_A$. This also implies that $A_B^{-1} = B_A$. This is what change of basis looks like in this notational framework.
Now, what is it that we want to do in this problem? We are given $T_A$ and $B_A$, and we want to calculate $T_B$. Given an arbitrary vector $v$, we have $$ v_A = B_Av_B\\ T_Av_A = T_AB_Av_B\\ B_A^{-1}T_Av_A = B_A^{-1}T_AB_Av_B $$ But the column vector $T_Av_A$ is the basis-$A$ representation of the vector $Tv$. Multiplying that by $B_A^{-1}$ transforms it into the basis-$B$ representation. So we have $$ B_A^{-1}T_Av_A = T_Bv_B $$ Inserting this, we get $$ T_Bv_B = B_A^{-1}T_AB_Av_B $$ Since the vector $v$, and thus the column vector $v_B$ was completely arbitrary, that means that we can factor it out of the above equation, and we get that $$ \boxed{T_B = B_A^{-1}T_AB_A} $$