I'm calculating the scattering matrix whose ideal form is $S = \left( \begin{array}{ccc} 0 &1 & 0 \\ 0 & 0 & 1 \\ 1 & 0 & 0 \end{array} \right) $.
My numerical result is however something like $S' = \left( \begin{array}{ccc} 0.0155571 & 0.67857 & 0.31505 \\ 0.0141489 & 0.30954 & 0.666379 \\ 0.972694 & 0.0225014 & 0.0176157 \end{array} \right)$.
I would like to define a fidelity function that tells how close $S'$ is to $S$; when $S' \equiv S$ the fidelity becomes unit and when $S'$ is very different from $S$ the fidelity becomes very small.