Trajectory of charged particle in a solenoid lens I was reading about how a Cathode ray tube works, and stumbled upon the term "focusing coil(s)". After a bit of reading I have deduced that this might be a focusing solenoid or solenoid lens. 
The working principle of the focusing solenoid seemed quite straightforward at first, and I decided to calculate a few particle trajectories myself. If the magnetic field of a solenoid is known, I would just have to solve equation of motion $\ddot{\mathbf{x}} = \frac{q}{m}\dot{\mathbf{x}}\times\mathbf{B}$.
However, the trajectories I got (see the figure) are not at all what I expected (see, for example, the particle trajectories presented here). 
I am quite sure that the magnetic field is calculated correctly. And in a uniform magnetic field my equation of motion predicts the circular motion with the expected gyroradius, but in this case - no focusing.
Therefore the obvious question: what am I doing wrong? Is there some additional force that I should account for or is my approach fundamentally flawed? 
Any input will be much appreciated!
The particle velocities should be small enough for non relativistic approximations to work.

 A: There are two focusing regimes for a solenoid.
The first is the weak, thin lens version which is probably what you are trying to achieve. For this the approximate focal length of the solenoid is written as
$1/f = B^2L/4(B\rho)^2$ where $(B\rho)$ is the rigidity of the particle, i.e. $(B\rho)=p/q$ where p is momentum and q is the charge.
The derivation and explanation ca be found at: http://home.fnal.gov/~prebys/misc/uspas_2014/Special%20Topic%20-%20Solenoids.pptx
My guess it that this is what you want, but you have simulated a set-up where the focal length is shorter than the solenoid. Try working out the above, and reduce the solenoid strength so the focal length is about twice the solenoid length.
By having too strong a field, I think the regime you have entered is usually used for transporting high intensity beams in a Brillouin flow regime, where the self repulsion of the particles is matched by the focusing solenoid field. In this case you are normally trying to transport the particles a long distance inside a solenoid, while accelerating the particles with another field.
You can read more about that regime here : http://didattica.uniroma2.it/files/scarica/insegnamento/168856-Acceleratori-Di-Particelle/45808-Lezione-19-Apr-17
A: If the solenoid satisfies certain conditions, it can mirror back the transverse velocities of the particles providing focusing. This is how they are often employed in accelerators, at least for the very-low energy stages.
However in the picture we are probably observing the effect of fringe fields. We can note that the oscillation frequency is higher within the loops, meaning that the field fades far from them. It looks like the field is generated by the orange current loops in the centre and therefore it opens up before and after them. Particles seem to follow the magnetic field lines, which is quite typical in the case of low energy and high fields.
