Solution (source code)

= Solution

In <cylindrical coordinates> the orthogonal <velocity> components are $\dot r$, $r\dot\theta$, $\dot z$. Their squared magnitudes add, and $\dot{\mathbf r}\cdot\mathbf A=\dot z A(r)$. Thus $\boxed{\mathcal L=m(\dot r^2+r^2\dot\theta^2+\dot z^2)/2+q\dot z A(r)}$. Taking the curl gives $B_\theta=-A'(r)$, consistent with the prescribed field.