What exactly this means in Dirac notation? I am pretty new to QM, I get the basics of Dirac notation. I understand this is the expectation value of an observable in a state $|\psi\rangle$ is given by:
$$\langle\hat A\rangle = \int\limits_{-\infty}^{\infty}\psi^*\hat A \psi\,\mathrm dx.$$
However, I am also given this in my lecture notes labelled "matrix element":
$$\langle\phi|\hat A|\psi\rangle = \int\limits_{-\infty}^{\infty}\phi^*\hat A \psi\,\mathrm dx.$$
My question is what does it mean to take the integral like this? And what is meant by the label "matrix element"? The expectation value integral makes sense to me since we are using the same state vector twice, but here we are using two separate state vectors.
 A: Let's start with some (discrete) orthonormal basis ${|m\rangle}$ such that $\langle m|n\rangle=\delta_{mn}$. To answer your second question: why is $\langle m|\hat A|n\rangle$ a matrix element? I'll generalize to a continuous basis in a second. We know that $\hat A$ is a linear operator. It takes a ket (vector) and spits out another ket (vector). Like this:
$$|\psi'\rangle=\hat A|\psi\rangle$$
You are used to multiplying matrices like this (I assume):
$$\pmatrix{a\\
2b\\3c}=\pmatrix{1&0&0\\0&2&0\\0&0&3}\pmatrix{a\\
b\\c}$$
But this way of multiplying matrices uses an implicit $basis$. The bra-ket notation is more abstract. It just says 'take this vector and apply this transformation to it'. If you have an orthonormal basis you can convert from the abstract notation to this more explicit notation. If you insert the completeness relation, $$\sum_m|m\rangle\langle m|=I,$$ into the abstract multiplication you get the following:
\begin{align}
\sum_m|m\rangle\langle m|\psi'\rangle&=\sum_m|m\rangle\langle m|\hat A|\sum_n|n\rangle\langle n|\psi\rangle\\
\sum_m|m\rangle\psi'_m&=\sum_{m,n}|m\rangle\langle m|\hat A|n\rangle\psi_n
\end{align}
Here $\psi_n$ means the n-component of $\psi$. This gives an independent equation for each $m$ so let's look at each $m-$component separately.
$$\psi'_m=\sum_n\langle m|\hat A|n\rangle\psi_n$$
Notice that $\langle m|\hat A|n\rangle$ is just a number, so define $A_{mn}=\langle m|\hat A|n\rangle$. You might not have recognised this yet but we have recovered the formula for matrix multiplication
$$\psi'_m=\sum_n A_{mn}\psi_n.$$
To make this even more clear take a cartesian basis, for example $$|1\rangle=\pmatrix{1\\0},|2\rangle=\pmatrix{0\\1},$$ some matrix $A=\pmatrix{a&b\\c&d}$ and convince yourself that $A_{12}=\langle 1|\hat A|2\rangle$.
In a continuous basis this still works the same, but to take a dot product in a continuous basis you have to take an integral instead of a sum.
