Is it possible for me to insert a vertical dotted line between the last two columns?
\begin{pmatrix}
1 & -1 & 0 & 0 & \cdots & 0 & a_1 \\
0 & 1 & -1 & 0 & \cdots & 0 & a_2 \\
0 & 0 & 1 & -1 & \cdots & 0 & a_3 \\
\vdots & \vdots & \vdots & \vdots & \ddots & \vdots \\
-1 & 0 & 0 & 0 & \cdots & 1 & a_n \\
\end{pmatrix}



nicematrixsolution that could be augmented with the answer below. I would say that they are sufficiently similar that the answers here would be acceptable there and then they're all kept together for future questioners. – Andrew Stacey Sep 11 '22 at 19:10