B will be a symbolic vector of size 1 x 2
U(1)=0.05*(1-tanh(B*(20*(x-0.5))));
On the right hand side, all of the symbolic vector B is used, so the right hand side will be a 1 x 2 result. But you are attempting to assign that 1 x 2 result into a single location, U(1)