My teacher hasn't explained it too well, so i'm looking for an explanation:

$$A = \begin{pmatrix} 0 & 1 & 1\\ 1 & 0 & 1\\ 1 & 1 & 0 \end{pmatrix}$$

$$A^2 = \begin{pmatrix} 2 & 1 & 1\\ 1 & 2 & 1\\ 1 & 1 & 2 \end{pmatrix}$$

I would have thought the first number in $A^2$ would be $0$, as $0 \cdot 0 = 0$, and am struggling to see where the $2$ comes from.

-
Let A be your matrix.Then $A^2$ is is same as A times A.Then compute A times A and you will obtain the $A^2$.If you do now know how to multiply matrix by matrix,I suggest you visit Khanacademy or view few youtube videos on subject.It is really simple – Vanio Begic Apr 13 '14 at 12:35

The first entry in $A^2$ comes from the first entry in $AA$, and that entry is $0\cdot 0 + 1\cdot 1 + 1 \cdot 1 = 2$.

Likewise, the entry in the first row, second column of $A^2$ is $0\cdot 1 + 1\cdot 0 + 1 \cdot 1 = 1$.

Perhaps you'll want to revisit matrix multiplication.

In particular, Wikipedia provides this example for arbitrary $3\times 3$ matricies:

Square matrices

If

$$\mathbf{A} = \begin{pmatrix} a & b & c \\ p & q & r \\ u & v & w \end{pmatrix}, \quad \mathbf{B} = \begin{pmatrix} \alpha & \beta & \gamma \\ \lambda & \mu & \nu \\ \rho & \sigma & \tau \\ \end{pmatrix}\,,$$

their matrix products are: $$\mathbf{AB} = \begin{pmatrix} a & b & c \\ p & q & r \\ u & v & w \end{pmatrix} \begin{pmatrix} \alpha & \beta & \gamma \\ \lambda & \mu & \nu \\ \rho & \sigma & \tau \\ \end{pmatrix} =\begin{pmatrix} a\alpha + b\lambda + c\rho & a\beta + b\mu + c\sigma & a\gamma + b\nu + c\tau \\ p\alpha + q\lambda + r\rho & p\beta + q\mu + r\sigma & p\gamma + q\nu + r\tau \\ u\alpha + v\lambda + w\rho & u\beta + v\mu + w\sigma & u\gamma + v\nu + w\tau \end{pmatrix}\,,$$

and

$$\mathbf{BA} = \begin{pmatrix} \alpha & \beta & \gamma \\ \lambda & \mu & \nu \\ \rho & \sigma & \tau \\ \end{pmatrix} \begin{pmatrix} a & b & c \\ p & q & r \\ u & v & w \end{pmatrix} =\begin{pmatrix} \alpha a + \beta p + \gamma u & \alpha b + \beta q + \gamma v & \alpha c + \beta r + \gamma w \\ \lambda a + \mu p + \nu u & \lambda b + \mu q + \nu v & \lambda c + \mu r + \nu w \\ \rho a + \sigma p + \tau u & \rho b + \sigma q + \tau v & \rho c + \sigma r + \tau w \end{pmatrix}\,.$$

-

There exists an operation of multiplication (that is NON commutative!) between matrices.

First it's fundamental that the number of column of the first matrix is equal to the number of rows of the second one; so you don't have any problem with $n\times n$ matrices, like yours one.

Second, the multiplication of two matrices gives a third matrix that is defined as follows: the element in position $(1,1)$ (i.e. first row, first column) is given by taking the first row of the first matrix $(a_1,a_2,\dots,a_n)$, and the first column of the second matrix $(b_1,b_2,\dots,b_n)^T$ and considering $a_1b_1+a_2b_2+\cdots+a_nb_n$.

Hence in your case, to get the element $(1,1)$ you have to compute $(0,1,1)\cdot(0,1,1)^T=0\cdot0+1\cdot1+1\cdot1=0+1+1=2$ as wanted.

-

$A^2$ is simply $A\cdot A$, where the $\cdot$ denotes matrix multiplication.

Matrices are not multiplied elementwise (other than for addition), but as follows:

The matrix element of the resulting matrix which sits on row $i$ and column $j$ is calculated by multiplying each element of $i$-th row of the first matrix with the corresponding element of the $j$-th column of the second matrix, and add up all those products. For your specific case, when interested in the upper left element of $$\begin{pmatrix}0&1&1\\1&0&1\\1&1&0\end{pmatrix}\cdot\begin{pmatrix}0&1&1\\1&0&1\\1&1&0\end{pmatrix}$$ you have to look at the first row of the first matrix, $$\begin{pmatrix}0&1&1\end{pmatrix}$$ and the first column of the second matrix, $$\begin{pmatrix}0\\1\\1\end{pmatrix}$$ and then find $0\cdot 0+1\cdot 1+1\cdot 1 = 2$. Therefore the upper left matrix element of the resulting matrix is $2$.

-

I think you're thinking of the Hadamard product (I think some books call this the direct product).