family of symmetric matrices and let us consider

$$\label{Hamiltonian}
\left\{
\begin{aligned}
Ju'(t)+S_\lambda(t)u(t)&=0,\quad t\in I\\
(u(0),u(1))\in \gamma_1(\lambda)&\times \gamma_2(\lambda),
\end{aligned}
\right.$$

as well as the differential operators

$$\begin{aligned}
\label{A-hamiltonian}
\mathcal{A}_\lambda:\mathcal{D}(\mathcal{A}_\lambda)\subset L^2(I,\mathbb{R}^{2n})\rightarrow L^2(I,\mathbb{R}^{2n}),\quad (\mathcal{A}_\lambda u)(t)=Ju'(t)+S_\lambda(t)u(t) \end{aligned}$$

on the domains $\mathcal{D}(\mathcal{A}_\lambda)=\{u\in H^1(I,\mathbb{R}^{2n}):\, u(0)\in \gamma_1(\lambda),\, u(1)\in \gamma_2(\lambda)\}$.\
We denote for $\lambda\in I$ by $\Psi_\lambda:I\rightarrow\operatorname{Sp}(2n,\mathbb{R})$ the matrices defined by

$$\label{Psi}
\left\{
\begin{aligned}
J\Psi'_\lambda(t)+S_\lambda(t)\Psi_\lambda(t)&=0,\quad t\in I\\
\Psi_\lambda(0)&=I_{2n},
\end{aligned}
\right.$$

and we set $(\Psi\gamma_1)(\lambda)=\Psi_\lambda(1) \gamma_1(\lambda)$. The aim of this final section is to obtain the following spectral flow formula from Theorem \[main\].

\[thm-Hamiltonian\] Under the assumptions above, $\mathcal{A}$ is a gap-continuous path of selfadjoint Fredholm operators on $L^2(I,\mathbb{R}^{2n})$ and

$$\operatorname{sf}(\mathcal{A})=\mu_{Mas}(\Psi\gamma_1,\gamma_2).$$

We define a continuous family of bounded invertible operators on $L^2(I,\mathbb{R}^{2n})$ by $(M_\lambda u)(t)=\Psi_\lambda(t) u(t)$, $t\in I$. Then

$$\begin{aligned}
(M^T_\lambda\mathcal{A}_\lambda M_\lambda u)(t)&= \Psi^T_\lambda(t)(J\Psi'_\lambda(t)u(t)+J\Psi_\lambda(t)u'(t)+S_\lambda(t)\Psi_\lambda(t)u(t))\\
&=\Psi^T_\lambda(t)(-S_\lambda(t)\Psi_\lambda(t)u(t))+\Psi^T_\lambda(t)J\Psi_\lambda(t)u'(t)+\Psi^T_\lambda(t)S_\lambda(t)\Psi_\lambda(t)u(t)\\
&=Ju'(t)\end{aligned}$$

and

$$\begin{aligned}
\mathcal{D}(M^T_\lambda\mathcal{A}_\lambda M_\lambda)&= M^{-1}_\lambda(\mathcal{D}(\mathcal{A}_\lambda))=\{u\in H^1(I,\mathbb{R}^{2n}):\, u(0)\in\gamma_1(\lambda), u(1)\in \Psi_\lambda(1)^{-1}\gamma_2(\lambda)\}.\end{aligned}$$

By Theorem \[main\], $M^T\mathcal{A}M$ is gap-continuous, and it follows from Lemma \[lemma-conjuagtion\] that $\mathcal{A}$ is gap-continuous as well. Moreover, we obtain from Theorem \[main\] and that

$$\operatorname{sf}(\mathcal{A})=\operatorname{sf}(M^T\mathcal{A}M)=\mu_{Mas}(\gamma_1,\Psi_{(\cdot)}(1)^{-1}\gamma_2)=\mu_{Mas}(\Psi\gamma_1,\gamma_2).$$

Note that we obtain from $\Psi$ and $\gamma_1$ further pairs of paths in $\Lambda(n)$ by

$$I\ni t\mapsto \Psi_0(t)\gamma_1(0)\in\Lambda(n),\quad I\ni t\mapsto\Psi_1(t)\gamma_1(1)\in\Lambda(n).$$ The following corollary is an easy reformulation of the previous theorem.

\[cor-Hamiltonian\] Under the previous assumptions,

$$\operatorname{sf}(\mathcal{A})=\mu_{Mas}(\Psi_1(\cdot)\gamma_1(1),\gamma_2(1))+\mu_{Mas}(\gamma_1,\gamma_2)-\mu_{Mas}(\Psi_0(\cdot)\gamma_1(0),\gamma_2(0)).$$

