# Matlab code for plotting magnetic scalar potential of a sextupole

1. Jul 12, 2009

### TooFastTim

First let me introduce myself. I'm and electronics engineer with 10 years of experience in the instrumentation of particle beams. I left the field for 10 years and have been fortunate to be granted a second lease of life on particle accelerators. Slowly over time the job has come to involve more and more control of beams so I'm trying to clue myself up on the "mechanics" of the magnets commonly used (e.g. dipole, quads and sextupoles). I've managed to get my head around dipoles (easy) and quads (not so easy and very subtle) but I've run into a dead-end (for me) regarding the magnetic scalar potential for a sextupole. I'm trying to plot it in either matlab or scilab but it ain't so simple. The maths I think I've got a resonable handle on considering it's fifteen years since i studied this.

So the equation describing the magnetic scalar potentials in cartesian co-ords is:

3*y*x^2+y^3=V/C

where V is the scalar potential and c is a constant. All of this is well & fine but the blasted thing goes complex on me. (actually it's a complete beast because you need to calculate the roots of a cubic equation to plot. Not difficult but very tedious) I have the same result if I use the cylindrical co-ords:

((V/C*sin(3*theta))*(0.333))*sin(theta).

In the previous institute at which I worked I had lots of support for this stuff but not at the present. So can anybody help me get my heard around this? Has anybody plotted the magnetic scalar potentials for a sextupole? Or can anybody explain what it means when it goes complex, bearing in mind I'm a humble electronics engineer who hasn't had to deal with thsi stuff since uni?