8 ESTRUCTURA DEL PROYECTO. Rungekutta.mLensSystem.mLens.mDipoleField.m
9 LensSystem.m function B = lensSystem(R,MUT,Z,nl,r) % This function calculates the magnetic field at several points calling the% function lens three times. The system is going to be composed by three% magnetic lens located at a distance z1, z2, z3 from the origin.% Input:% R: Radius of the lens, in m.% Mut: Dipole moment given as a matrix 4xn in which 4 rows defines the dipolar moment of a every lens, in T*m^2.% Z: Distance from the origin, given as a vector 1xn, in m.% r: Matrix of nx3 dimensions in which the magnetic field is going to be% calculated, in m.% nl: Number of lens that form the system.% Output:
10 Lens.m function B= lens( R, mu, z, r) % This function calculates the magnetic field created by a quadrupole% magnetic, which is formed by 4 dipoles. It?s needed a matrix mu, formed% by 4 magnetic moments and the distance between the origin and every% dipole, generated by z+R.% Input:% R: Distance from the centre of the dipole to each dipole (radius), in m.% mu: Matrix(4x3) with the magnetic moment of 4 dipoles, in m^2*A.% z: Distance from the origin to the centre of the lens, in m.% r: Vector from the origin to an arbitrary point, in m.
11 DipoleField.m function B = DipoleField( mu, rmu, r ) % This function calculates the magnetic field created by a dipole, given% the dipole moment, the distance between the dipole and the origin, and% the distance r from the origin to an arbitrary point r.% Input: Everything in 3D.% mu: Dipole moment, in m^2 * A.% rmu: Distance between the origin and the dipole, in m.% r: Distance between the origin and a point r, in m.% Output:% B: Magnetic field at a point, in T.
12 FLORENTZ% This function calculates the force on a particle created by the action of% a Magnetic Field, in our case, the particles are electrons.% The form of the force is F= q*vxB, where q is the charge in C, v the% speed, in m/s and B is the Magnetic Field in T.% Input:% v: Speed of the particle, we are supposing it constant, in m/s.% r: Matrix of nx3 dimensions in which the magnetic field is going to be% calculated calling lensSystem, in m.% Output:% F: Force suffered by the particle, in N.