Welcome back.
So we ended up generating our starting configuration.
We have an array called quartz, which contains the coordinates of these red dots, which are the positions
of the magnetic moments.
And then we have another array called Mark, which contains the information about the blue arrows,
which are the magnetic moments themselves.
And now we want to bring order into this whole mess and we want to find the state, which is characterized
by the lowest energy.
And for this, we will use the Monte Carlo algorithm.
But before we can use it, we must first specify the energy.
We must say what is actually the function that describes the energy that we want to minimize.
And here this is one of the most simple terms that you can consider for describing a ferromagnetic.
This is called the exchange interaction, or sometimes also called Heisenberg interaction or Heisenberg
Exchange.
So here you have a sum over all magnetic moments of the sample.
These are indexed by I and J in this case, and you just calculate the scalar dot product.
So here we have a sum, and this is already a bit of a more special case or a bit of a simplified case
because these funny looking brackets here, they indicate, indicate only direct nearest neighbors.
So in general, you would sum up of all of these pairs and then you would consider the distance between
magnetic moments and the four that they are apart, the weaker the interaction will be.
But we can make it much, much easier, and we can see only the nearest only.
The direct neighbors contribute to this interaction.
And every other neighbors will not contribute at all because the interaction is just very, very weak.
That's a bit of a simplification and approximation, but I think it's really useful to use this.
All right.
So what does that mean?
So we sum up over Paris here over Paris, and then we calculate the scalar product and we can think
now which configuration do we think will minimize the energy?
Well, in this case, it's actually quite easy, and we can come up with the solution ourselves because
if we only have this term, then the lowest energy, if we say g is positive will be when all of these
segments here, all of these terms will be maximum and they are maximum.
If these two vectors a parallel to each other, then it is just one times one times cosine of zero,
which is one.
So then we just sum up another one.
So as long as am I and MJ a parallel to each other, this term will be maximum.
And since we sum up, we must maximize all of the neighbors.
So this means all the moments in the sample should point along the same direction, and this is what
characterizes a fairer mechanism.
So if we say we take this function here for the energy, then we should end up in the end with a configuration
where every moment is parallel to each other.
So we should then start from here, run on one to Carlo algorithm and end up with a fairer mechanism.
Of course, this single term does not describe the whole reality.
There are additional energy terms that we do not consider for now.
And also, there are even more difficult terms that lead to noncore linear spin textures that we will
consider in the later part of the course.
But for now, let's stick with this energy because here we know already what will be the result, and
it's a nice test for our algorithm that we will program in the next few lectures.
So first of all, before we can come to the metropolis step, we must define the energy.
So I will, right, define energy.
And since we will add other terms later on, I will give this a different name.
I would call it energy exchange, and the argument will only be mark, which is the array of the magnetization.
So we can right here as a comment mark.
Hurray to the transition or magnetic moments.
OK, so we start with an energy of zero and then we will run loops and add up the contributions.
So for X in range length?
And for y in range lengths.
Energy is equal to energy plus, and then we must program what is written down here, and in the end,
we will return to value energy.
So here we could not just go ahead and programmed this, but I will use here another function because
this will come in handy.
Later on, I will call this energy exchange contribution.
And again, the argument will be Mac, and then we must also specify the indices.
So we must give it to other arguments X and Y.
So now, of course, we must specify this function, so I, right, define energy exchange contribution
and now we can right here the individual term.
So we will return minus 0.5 times J Times and then the Dot product so and p dot dot and then two vectors.
So Vector one comma factor two.
OK.
So how does that work?
We should tested before we program it.
So Vector one will probably be magnetization, and then we tested this before we should use all three
components.
And then we specified here the index, for example, five comma to come on zero.
This would be one of these vectors.
And then we can calculate the dot product and P Dot with one of the neighbors.
For example, six to zero.
So this would then be two of these neighbors.
However, this is not the only one we have to add here several terms.
So we have to also consider the left neighbor.
And then we have to also consider the upper neighbor and a lower neighbor.
So we have to add up four of these dot products.
Or we could also see we calculate the dot product of this vector with this some of this vector, this
vector and the other two vectors, and that's maybe a bit easier to do or a bit shorter to right.
And also it runs a bit faster and the code.
So this would be in this case, magnetization for two plus marketisation.
Five.
Three plus magnetization.
Five one.
And then, of course, we must specify.
Jay, let's say it's just one doesn't really matter here.
And then we must try and 0.5 times j times this.
Of course, I have to run it first.
So, yeah, this would be the contribution to the energy from one particular magnetic moment from one
set of these indices.
So now the only thing that is difficult is what happens if we are at the edge.
For example, what happens?
If our ex would not be five, but it would be zero, so then we would have here one here, we would
have zero zero.
But here we would have no neighbor.
And to make it a bit more simple, what we typically do in physics is we consider so-called periodic
boundary conditions.
So this means an atom that is at the edge, which has one of these indices.
Zero, for example, does not only interact with the three nearest neighbors, but would also interact
with the atom on the other side of the sample.
So basically, you take this whole thing and you make it periodic.
You place it one more time here, one more time here, here and here.
So this way, it's much easier to program this.
So this means here we would have an index, then I'm sorry here.
We would have an index then of
here of minus one, which of course, doesn't work because it or it doesn't work.
Yeah, of course it does work in this case.
But what does not work is if we take the highest possible index, for example, if we have here the
index length.
Minus one, which is the highest possible index, this would be the atom on this side.
So then we would have here.
Length.
Minus two.
This would be no problem.
He would have length minus one length minus one.
And here we would have length.
And this gives a problem now because length is out of the range.
So instead of writing here length, we must actually write zero.
And to do this, we could, of course, right here zero.
But if we want to do it automatically, we have to use the modulo function so we can right here modulo
length.
And this works if we do this for all of these terms.
So here and here.
And here, Pitt will still give the correct result.
OK, so this was just for practice, and now we can really implement it.
So as I said, here comes the actual actor.
So this would be magnetization,
the indices would be X, Y and zero.
And then here we are, right magnetization.
X plus one.
Then Class X minus one.
Plus.
X and Y plus one and Y minus one.
And as I said, we must divide all of these ones, here are we add one, we subtract one with the length
and calculate the module.
So this is just that we don't run into any trouble at the edges.
For the interior, we wouldn't really need this.
OK.
So I think I can delete this now.
It was just for practice and I hope this works now, but it it looks pretty good, I think.
OK, so this means we have now calculated our total energy and we could not just go ahead and write
what is the energy exchange of our magnetic moments?
It is two point eight.
Let's just rerun everything again.
So we start with a new, randomly generated array of magnetic moments.
This time it is five point nine.
Let's do it one more time.
This time it's negative, minus twenty six.
And the truth is, if we do this over and over again, then the total energy would be zero.
This is because we have just a totally random orientation.
So this cross product here and across product, this dot product can take any value between minus one
and one.
And so if you have many of these terms that are somewhere a randomly chosen between these two numbers,
then it will cancel out and it will give zero in the end.
OK.
So where are we now?
We have now our coordinates.
We have our magnetic moments and we can calculate the energy of our current set up by calling this function.
And this we need for the next step where we will program the Metropolis Step, which is basically the
core feature of the Monte Carlo algorithm.
And I will explain this to you in the next lecture.
But you see, already we have to calculate the energy, and for this, we have programmed here our new
function.