1
00:00:00,210 --> 00:00:00,990
Welcome back.

2
00:00:01,110 --> 00:00:04,890
So we ended up generating our starting configuration.

3
00:00:05,370 --> 00:00:11,250
We have an array called quartz, which contains the coordinates of these red dots, which are the positions

4
00:00:11,250 --> 00:00:12,720
of the magnetic moments.

5
00:00:13,200 --> 00:00:19,290
And then we have another array called Mark, which contains the information about the blue arrows,

6
00:00:19,830 --> 00:00:22,110
which are the magnetic moments themselves.

7
00:00:22,920 --> 00:00:29,970
And now we want to bring order into this whole mess and we want to find the state, which is characterized

8
00:00:29,970 --> 00:00:31,240
by the lowest energy.

9
00:00:31,260 --> 00:00:34,530
And for this, we will use the Monte Carlo algorithm.

10
00:00:35,340 --> 00:00:39,000
But before we can use it, we must first specify the energy.

11
00:00:39,000 --> 00:00:43,890
We must say what is actually the function that describes the energy that we want to minimize.

12
00:00:44,760 --> 00:00:51,960
And here this is one of the most simple terms that you can consider for describing a ferromagnetic.

13
00:00:52,470 --> 00:00:58,470
This is called the exchange interaction, or sometimes also called Heisenberg interaction or Heisenberg

14
00:00:58,470 --> 00:00:59,160
Exchange.

15
00:00:59,580 --> 00:01:04,349
So here you have a sum over all magnetic moments of the sample.

16
00:01:04,739 --> 00:01:11,130
These are indexed by I and J in this case, and you just calculate the scalar dot product.

17
00:01:12,180 --> 00:01:19,890
So here we have a sum, and this is already a bit of a more special case or a bit of a simplified case

18
00:01:20,280 --> 00:01:27,140
because these funny looking brackets here, they indicate, indicate only direct nearest neighbors.

19
00:01:27,870 --> 00:01:34,260
So in general, you would sum up of all of these pairs and then you would consider the distance between

20
00:01:34,260 --> 00:01:38,880
magnetic moments and the four that they are apart, the weaker the interaction will be.

21
00:01:39,300 --> 00:01:43,380
But we can make it much, much easier, and we can see only the nearest only.

22
00:01:43,380 --> 00:01:46,650
The direct neighbors contribute to this interaction.

23
00:01:47,010 --> 00:01:53,040
And every other neighbors will not contribute at all because the interaction is just very, very weak.

24
00:01:53,520 --> 00:02:00,240
That's a bit of a simplification and approximation, but I think it's really useful to use this.

25
00:02:01,230 --> 00:02:01,620
All right.

26
00:02:01,620 --> 00:02:02,760
So what does that mean?

27
00:02:03,000 --> 00:02:10,800
So we sum up over Paris here over Paris, and then we calculate the scalar product and we can think

28
00:02:10,800 --> 00:02:15,130
now which configuration do we think will minimize the energy?

29
00:02:15,840 --> 00:02:21,120
Well, in this case, it's actually quite easy, and we can come up with the solution ourselves because

30
00:02:21,120 --> 00:02:29,070
if we only have this term, then the lowest energy, if we say g is positive will be when all of these

31
00:02:29,070 --> 00:02:34,580
segments here, all of these terms will be maximum and they are maximum.

32
00:02:34,590 --> 00:02:41,610
If these two vectors a parallel to each other, then it is just one times one times cosine of zero,

33
00:02:41,610 --> 00:02:42,300
which is one.

34
00:02:42,630 --> 00:02:44,820
So then we just sum up another one.

35
00:02:45,840 --> 00:02:51,930
So as long as am I and MJ a parallel to each other, this term will be maximum.

36
00:02:52,770 --> 00:02:56,460
And since we sum up, we must maximize all of the neighbors.

37
00:02:56,790 --> 00:03:02,220
So this means all the moments in the sample should point along the same direction, and this is what

38
00:03:02,220 --> 00:03:03,960
characterizes a fairer mechanism.

39
00:03:05,040 --> 00:03:14,070
So if we say we take this function here for the energy, then we should end up in the end with a configuration

40
00:03:14,070 --> 00:03:16,590
where every moment is parallel to each other.

41
00:03:17,310 --> 00:03:23,040
So we should then start from here, run on one to Carlo algorithm and end up with a fairer mechanism.

42
00:03:24,120 --> 00:03:27,810
Of course, this single term does not describe the whole reality.

43
00:03:28,020 --> 00:03:32,340
There are additional energy terms that we do not consider for now.

44
00:03:32,700 --> 00:03:38,580
And also, there are even more difficult terms that lead to noncore linear spin textures that we will

45
00:03:38,580 --> 00:03:40,650
consider in the later part of the course.

46
00:03:41,490 --> 00:03:47,070
But for now, let's stick with this energy because here we know already what will be the result, and

47
00:03:47,070 --> 00:03:51,840
it's a nice test for our algorithm that we will program in the next few lectures.

48
00:03:53,720 --> 00:03:59,570
So first of all, before we can come to the metropolis step, we must define the energy.

49
00:04:00,200 --> 00:04:02,570
So I will, right, define energy.

50
00:04:03,170 --> 00:04:07,400
And since we will add other terms later on, I will give this a different name.

51
00:04:07,400 --> 00:04:15,530
I would call it energy exchange, and the argument will only be mark, which is the array of the magnetization.

52
00:04:16,790 --> 00:04:20,029
So we can right here as a comment mark.

53
00:04:20,810 --> 00:04:23,960
Hurray to the transition or magnetic moments.

54
00:04:27,450 --> 00:04:35,640
OK, so we start with an energy of zero and then we will run loops and add up the contributions.

55
00:04:36,270 --> 00:04:40,260
So for X in range length?

56
00:04:42,950 --> 00:04:47,240
And for y in range lengths.

57
00:04:49,220 --> 00:04:56,300
Energy is equal to energy plus, and then we must program what is written down here, and in the end,

58
00:04:56,990 --> 00:04:59,750
we will return to value energy.

59
00:05:01,280 --> 00:05:06,620
So here we could not just go ahead and programmed this, but I will use here another function because

60
00:05:06,620 --> 00:05:08,630
this will come in handy.

61
00:05:08,630 --> 00:05:14,270
Later on, I will call this energy exchange contribution.

62
00:05:15,300 --> 00:05:20,270
And again, the argument will be Mac, and then we must also specify the indices.

63
00:05:20,450 --> 00:05:23,660
So we must give it to other arguments X and Y.

64
00:05:24,990 --> 00:05:32,760
So now, of course, we must specify this function, so I, right, define energy exchange contribution

65
00:05:32,760 --> 00:05:35,940
and now we can right here the individual term.

66
00:05:36,270 --> 00:05:52,950
So we will return minus 0.5 times J Times and then the Dot product so and p dot dot and then two vectors.

67
00:05:52,960 --> 00:05:56,130
So Vector one comma factor two.

68
00:05:58,260 --> 00:05:58,740
OK.

69
00:05:58,860 --> 00:06:00,360
So how does that work?

70
00:06:00,450 --> 00:06:03,210
We should tested before we program it.

71
00:06:03,870 --> 00:06:10,440
So Vector one will probably be magnetization, and then we tested this before we should use all three

72
00:06:10,440 --> 00:06:11,200
components.

73
00:06:11,610 --> 00:06:16,380
And then we specified here the index, for example, five comma to come on zero.

74
00:06:17,250 --> 00:06:18,780
This would be one of these vectors.

75
00:06:19,320 --> 00:06:26,670
And then we can calculate the dot product and P Dot with one of the neighbors.

76
00:06:28,510 --> 00:06:31,390
For example, six to zero.

77
00:06:33,280 --> 00:06:35,410
So this would then be two of these neighbors.

78
00:06:36,130 --> 00:06:40,360
However, this is not the only one we have to add here several terms.

79
00:06:41,740 --> 00:06:44,350
So we have to also consider the left neighbor.

80
00:06:45,010 --> 00:06:48,880
And then we have to also consider the upper neighbor and a lower neighbor.

81
00:06:49,510 --> 00:06:52,240
So we have to add up four of these dot products.

82
00:06:53,140 --> 00:07:01,720
Or we could also see we calculate the dot product of this vector with this some of this vector, this

83
00:07:01,720 --> 00:07:07,600
vector and the other two vectors, and that's maybe a bit easier to do or a bit shorter to right.

84
00:07:07,600 --> 00:07:09,610
And also it runs a bit faster and the code.

85
00:07:10,480 --> 00:07:18,370
So this would be in this case, magnetization for two plus marketisation.

86
00:07:19,390 --> 00:07:20,080
Five.

87
00:07:21,070 --> 00:07:24,160
Three plus magnetization.

88
00:07:24,400 --> 00:07:25,810
Five one.

89
00:07:28,360 --> 00:07:30,970
And then, of course, we must specify.

90
00:07:31,310 --> 00:07:34,930
Jay, let's say it's just one doesn't really matter here.

91
00:07:35,320 --> 00:07:40,420
And then we must try and 0.5 times j times this.

92
00:07:41,560 --> 00:07:43,150
Of course, I have to run it first.

93
00:07:43,750 --> 00:07:50,920
So, yeah, this would be the contribution to the energy from one particular magnetic moment from one

94
00:07:50,920 --> 00:07:52,240
set of these indices.

95
00:07:54,580 --> 00:08:00,820
So now the only thing that is difficult is what happens if we are at the edge.

96
00:08:01,360 --> 00:08:02,950
For example, what happens?

97
00:08:04,570 --> 00:08:13,330
If our ex would not be five, but it would be zero, so then we would have here one here, we would

98
00:08:13,330 --> 00:08:14,680
have zero zero.

99
00:08:15,100 --> 00:08:18,250
But here we would have no neighbor.

100
00:08:19,030 --> 00:08:24,010
And to make it a bit more simple, what we typically do in physics is we consider so-called periodic

101
00:08:24,010 --> 00:08:25,120
boundary conditions.

102
00:08:25,690 --> 00:08:30,920
So this means an atom that is at the edge, which has one of these indices.

103
00:08:31,040 --> 00:08:37,539
Zero, for example, does not only interact with the three nearest neighbors, but would also interact

104
00:08:37,539 --> 00:08:40,659
with the atom on the other side of the sample.

105
00:08:41,679 --> 00:08:44,770
So basically, you take this whole thing and you make it periodic.

106
00:08:44,770 --> 00:08:48,490
You place it one more time here, one more time here, here and here.

107
00:08:49,240 --> 00:08:52,000
So this way, it's much easier to program this.

108
00:08:53,110 --> 00:08:58,360
So this means here we would have an index, then I'm sorry here.

109
00:08:58,660 --> 00:09:00,670
We would have an index then of

110
00:09:03,790 --> 00:09:10,700
here of minus one, which of course, doesn't work because it or it doesn't work.

111
00:09:10,870 --> 00:09:12,700
Yeah, of course it does work in this case.

112
00:09:14,380 --> 00:09:22,900
But what does not work is if we take the highest possible index, for example, if we have here the

113
00:09:22,900 --> 00:09:23,890
index length.

114
00:09:26,040 --> 00:09:31,770
Minus one, which is the highest possible index, this would be the atom on this side.

115
00:09:33,510 --> 00:09:35,070
So then we would have here.

116
00:09:38,780 --> 00:09:39,410
Length.

117
00:09:39,830 --> 00:09:40,770
Minus two.

118
00:09:40,790 --> 00:09:41,990
This would be no problem.

119
00:09:42,290 --> 00:09:45,200
He would have length minus one length minus one.

120
00:09:45,650 --> 00:09:47,450
And here we would have length.

121
00:09:47,820 --> 00:09:52,820
And this gives a problem now because length is out of the range.

122
00:09:53,330 --> 00:09:56,870
So instead of writing here length, we must actually write zero.

123
00:09:57,800 --> 00:10:00,530
And to do this, we could, of course, right here zero.

124
00:10:00,530 --> 00:10:08,060
But if we want to do it automatically, we have to use the modulo function so we can right here modulo

125
00:10:08,060 --> 00:10:08,450
length.

126
00:10:09,770 --> 00:10:13,070
And this works if we do this for all of these terms.

127
00:10:15,440 --> 00:10:17,600
So here and here.

128
00:10:21,000 --> 00:10:25,530
And here, Pitt will still give the correct result.

129
00:10:30,520 --> 00:10:35,230
OK, so this was just for practice, and now we can really implement it.

130
00:10:35,890 --> 00:10:38,410
So as I said, here comes the actual actor.

131
00:10:38,920 --> 00:10:41,200
So this would be magnetization,

132
00:10:44,320 --> 00:10:46,420
the indices would be X, Y and zero.

133
00:10:47,680 --> 00:10:50,650
And then here we are, right magnetization.

134
00:10:52,470 --> 00:10:54,320
X plus one.

135
00:10:58,100 --> 00:11:01,450
Then Class X minus one.

136
00:11:04,040 --> 00:11:04,790
Plus.

137
00:11:07,570 --> 00:11:13,180
X and Y plus one and Y minus one.

138
00:11:15,060 --> 00:11:23,070
And as I said, we must divide all of these ones, here are we add one, we subtract one with the length

139
00:11:23,880 --> 00:11:25,210
and calculate the module.

140
00:11:26,640 --> 00:11:30,210
So this is just that we don't run into any trouble at the edges.

141
00:11:32,470 --> 00:11:34,690
For the interior, we wouldn't really need this.

142
00:11:35,620 --> 00:11:35,980
OK.

143
00:11:36,190 --> 00:11:38,260
So I think I can delete this now.

144
00:11:38,560 --> 00:11:44,860
It was just for practice and I hope this works now, but it it looks pretty good, I think.

145
00:11:45,610 --> 00:11:51,520
OK, so this means we have now calculated our total energy and we could not just go ahead and write

146
00:11:52,210 --> 00:11:57,700
what is the energy exchange of our magnetic moments?

147
00:11:58,240 --> 00:11:59,740
It is two point eight.

148
00:12:00,700 --> 00:12:02,950
Let's just rerun everything again.

149
00:12:02,950 --> 00:12:07,210
So we start with a new, randomly generated array of magnetic moments.

150
00:12:07,660 --> 00:12:09,640
This time it is five point nine.

151
00:12:10,480 --> 00:12:11,560
Let's do it one more time.

152
00:12:13,360 --> 00:12:15,520
This time it's negative, minus twenty six.

153
00:12:16,300 --> 00:12:22,270
And the truth is, if we do this over and over again, then the total energy would be zero.

154
00:12:22,750 --> 00:12:25,870
This is because we have just a totally random orientation.

155
00:12:26,260 --> 00:12:32,560
So this cross product here and across product, this dot product can take any value between minus one

156
00:12:32,560 --> 00:12:33,070
and one.

157
00:12:33,700 --> 00:12:40,150
And so if you have many of these terms that are somewhere a randomly chosen between these two numbers,

158
00:12:40,150 --> 00:12:43,630
then it will cancel out and it will give zero in the end.

159
00:12:45,010 --> 00:12:45,400
OK.

160
00:12:46,000 --> 00:12:46,810
So where are we now?

161
00:12:46,840 --> 00:12:49,000
We have now our coordinates.

162
00:12:49,000 --> 00:12:55,540
We have our magnetic moments and we can calculate the energy of our current set up by calling this function.

163
00:12:56,350 --> 00:13:02,170
And this we need for the next step where we will program the Metropolis Step, which is basically the

164
00:13:02,170 --> 00:13:04,570
core feature of the Monte Carlo algorithm.

165
00:13:05,260 --> 00:13:07,240
And I will explain this to you in the next lecture.

166
00:13:07,240 --> 00:13:13,570
But you see, already we have to calculate the energy, and for this, we have programmed here our new

167
00:13:13,570 --> 00:13:14,050
function.

