# Numerical integration of a magnetic spin vector in a magnetic field

1. Aug 21, 2013

### chaiyar

1. The problem statement, all variables and given/known data

Hi there, thanks in advance for any help!

I have a first order DE: $$\frac{\partial \vec{m}}{\partial t} = -\vec{m} \times \vec{h}_{eff} + \alpha \vec{m} \times \frac{\partial \vec{m}}{\partial t}$$ (a scaled Landau-Lifshitz-Gilbert equation)

where m is a magnetism vector, alpha is a damping factor and h is an effective uniform magnetic field.

I'm trying to numerically integrate it with the Euler method to get a precession of the spin vector around the h vector.

So far I've integrated the first term but the second, damping term I can't see how to translate into code.. (in C++)

So essentially what I've done is assumed the magnetic field to be aligned in the z-direction, and written
Code (Text):
for(i=1 ; i<=tmax ; i++) {

mx = mx + h * -my;
my = my + h *  mx;
t = t + h;
for the first term, where mx is the x-component of the m vector etc. and h is the timestep, and I need to add the damping term onto the end.

Considering the x-component first, presumably the derivative in the damping term has to be put down as m_x as well, but what direction is the other m vector to be taken in?

Sorry if that's not very well asked, but thanks a lot for any help!

Last edited: Aug 21, 2013
2. Aug 21, 2013

### TSny

Hello, chaiyar.

If you write out the DE for each component (x, y, z), you will get three equations that are linear in $\dot{m_x}, \dot{m_y}, \dot{m_z}$, where the dot denotes time derivative.

Algebraically solving these simultaneously for $\dot{m_x}, \dot{m_y}, \dot{m_z}$, you can get equations of the form

$\dot{m_x} = f_1(m_x, m_y, m_z)$
$\dot{m_y} = f_2(m_x, m_y, m_z)$
$\dot{m_z} = f_3(m_x, m_y, m_z)$

for certain functions $f_1, f_2, f_3$ .

Then you can use these equations with the Euler method to step forward in time.

3. Aug 22, 2013

### chaiyar

Thanks for your help TSny, but I'm still a little lost.

I end up with three equations of the form

$$\dot{m}_x = f_1 (m_y,m_z,\dot{m}_y,\dot{m}_z) \\ \dot{m}_y = f_2 (m_x,m_z,\dot{m}_x,\dot{m}_z) \\ \dot{m}_z = f_3 (m_x,m_y,\dot{m}_x,\dot{m}_y) \\$$

but I don't see how to incorporate the time derivatives into the program.. Do I have to take the equations further to get rid of the derivatives by using Lagrange multipliers or something like that?

Thanks again!

4. Aug 22, 2013

### voko

You have three equations that are linear in $\dot{m}_i$, so you always can convert them to $\dot{m}_i = f(...)$, where the right hand side is independent of $\dot{m}_i$.