1
00:00:00,630 --> 00:00:09,150
So we start our numerical solution for the heat equation by actually this.

2
00:00:09,690 --> 00:00:11,550
Well, Jupyter Notebook.

3
00:00:11,820 --> 00:00:13,200
Will I like Jupyter Notebook?

4
00:00:13,230 --> 00:00:18,000
Of course, because it's easy to see how the numbers are changing.

5
00:00:18,660 --> 00:00:24,030
And so we start by just writing the name of the of the file.

6
00:00:24,030 --> 00:00:27,930
And in our case, we can call it, well, heat.

7
00:00:29,210 --> 00:00:30,860
It's Maine.

8
00:00:31,130 --> 00:00:38,240
And now we have the file and we can press save just to make sure that the file is actually saved.

9
00:00:38,450 --> 00:00:48,590
So starting with, well, our solution, it's all usual libraries because, uh, because we will write

10
00:00:48,590 --> 00:00:51,020
everything by most of the things by ourselves.

11
00:00:51,020 --> 00:00:53,960
So we first need to import.

12
00:00:54,680 --> 00:00:59,420
We make it a little bit like zoom in, import numpy.

13
00:01:00,380 --> 00:01:02,270
And from.

14
00:01:03,320 --> 00:01:12,740
Of course, Matlab, the numpy is for math and from matplotlib or matrices to be more accurate.

15
00:01:12,770 --> 00:01:14,120
Regarding the numpy.

16
00:01:14,150 --> 00:01:17,240
NumPy arrays by plot.

17
00:01:17,270 --> 00:01:18,980
To plot things.

18
00:01:19,280 --> 00:01:21,400
And of course shift and enter.

19
00:01:21,410 --> 00:01:25,850
So this means it got imported into the our system.

20
00:01:26,960 --> 00:01:38,090
Now, the first thing is we need to set some variables that in the well, in the like describing our

21
00:01:38,090 --> 00:01:41,790
system kind of or it is like what we call post-processing.

22
00:01:41,840 --> 00:01:48,470
So the first thing is we need the length of the rod, let's say, to be ten.

23
00:01:48,470 --> 00:01:55,070
And the reason I put a ten because I tested one meter, it's just it will diffuse too fast.

24
00:01:55,070 --> 00:02:04,250
So we'll just put it ten and K equals 0.89 and.

25
00:02:05,070 --> 00:02:05,760
Temp.

26
00:02:06,560 --> 00:02:10,580
Or temperature left equals.

27
00:02:10,700 --> 00:02:15,500
We can consider 100 degrees and temperature.

28
00:02:16,790 --> 00:02:17,360
At.

29
00:02:18,250 --> 00:02:19,210
Right?

30
00:02:19,510 --> 00:02:20,800
Right.

31
00:02:21,920 --> 00:02:24,100
Will be, let's say 200.

32
00:02:24,110 --> 00:02:31,730
So you will have in balance one is or in the left, you have 100, and on the right you have 200.

33
00:02:31,760 --> 00:02:32,420
So.

34
00:02:33,670 --> 00:02:35,800
The total simulation time.

35
00:02:35,830 --> 00:02:36,730
Total.

36
00:02:38,290 --> 00:02:39,430
All time.

37
00:02:40,570 --> 00:02:46,480
Our simulation time well equals ten and shifted.

38
00:02:47,050 --> 00:02:55,870
So now we decide or we considered a rod one temperature, one part or one end of it will have 100 degrees,

39
00:02:55,900 --> 00:02:58,050
the other end will have 200 degrees.

40
00:02:58,060 --> 00:03:05,320
And um, we will later define the initial condition, which is the rod itself will have a temperature

41
00:03:05,320 --> 00:03:06,040
of zero.

42
00:03:06,340 --> 00:03:07,960
So what does it mean?

43
00:03:07,960 --> 00:03:09,780
This is what we call boundary condition.

44
00:03:09,790 --> 00:03:11,110
The boundary condition is.

45
00:03:12,480 --> 00:03:17,250
At the right, it will be 200 degrees and the left will be 100 degrees.

46
00:03:17,980 --> 00:03:22,210
So the X equals 0.1.

47
00:03:22,210 --> 00:03:27,400
And of course, this is the value for aluminum and you can, of course, change it as you like.

48
00:03:27,430 --> 00:03:29,650
I think it's a little bit high.

49
00:03:29,650 --> 00:03:36,040
And yeah, just just put it wherever like for this thing you can put it any value one.

50
00:03:36,460 --> 00:03:43,300
But of course we if you're simulating an actual material now took the number is just for aluminum but

51
00:03:43,300 --> 00:03:50,980
if you simulate any an actual material you have to check the actual the material value itself.

52
00:03:50,980 --> 00:04:05,830
So we consider that we have a ten meter rod or like, Yeah, a rod and we have 0.1, which is the so

53
00:04:05,830 --> 00:04:10,030
you will have a oh point like ten centimeter basically.

54
00:04:10,900 --> 00:04:11,140
Yeah.

55
00:04:11,140 --> 00:04:16,300
Ten centimeter for every A this is the mesh you will calculate.

56
00:04:16,300 --> 00:04:16,930
So.

57
00:04:17,650 --> 00:04:21,880
What we will have is we will have the actual.

58
00:04:22,420 --> 00:04:23,280
Yeah, this one.

59
00:04:23,940 --> 00:04:33,420
We will have the actual road goes like this and here we will have 200 degrees.

60
00:04:33,420 --> 00:04:38,820
And here you will have um, just let me look at the left.

61
00:04:38,820 --> 00:04:39,600
100.

62
00:04:39,630 --> 00:04:40,740
Yeah, it's correct.

63
00:04:40,740 --> 00:04:43,440
100 is left and.

64
00:04:45,320 --> 00:04:47,900
And this is basically our road.

65
00:04:47,900 --> 00:04:53,330
And then what we will do is here we have a discretized.

66
00:04:53,660 --> 00:04:59,210
So every we will cut this road into small, small, small parts.

67
00:04:59,210 --> 00:05:05,990
And this part will be a 0.1 meter, of course.

68
00:05:06,110 --> 00:05:08,330
And of course the road is ten meter.

69
00:05:08,810 --> 00:05:12,440
Of course, this is just dummy value, just whatever it is.

70
00:05:12,800 --> 00:05:18,740
But and if you want to really, of course, solve this problem, you have to be careful about the physics.

71
00:05:20,070 --> 00:05:22,220
The physics values.

72
00:05:22,230 --> 00:05:24,960
So here the X equals 0.1.

73
00:05:25,830 --> 00:05:26,880
Now.

74
00:05:28,220 --> 00:05:32,030
What we need is we need the vector.

75
00:05:32,150 --> 00:05:33,170
Vector.

76
00:05:33,920 --> 00:05:36,340
Equals the x vector.

77
00:05:36,350 --> 00:05:46,200
So we will have this a road that has to be cut it for a very small portion of 0.1 meter, which is ten

78
00:05:46,200 --> 00:05:46,670
centimeter.

79
00:05:46,670 --> 00:05:48,910
So we need to cut it.

80
00:05:48,920 --> 00:05:59,900
So we say numpy, we will make a basically a list of values or, or more like it's a numpy array of

81
00:05:59,900 --> 00:06:03,050
these values that will increase little by little.

82
00:06:03,050 --> 00:06:06,140
So we have a numpy line.

83
00:06:06,350 --> 00:06:07,730
Space.

84
00:06:08,000 --> 00:06:12,020
It will start from zero until the length.

85
00:06:12,740 --> 00:06:18,200
The length of the rod with an interval of.

86
00:06:19,570 --> 00:06:22,300
A length of the rod.

87
00:06:23,240 --> 00:06:24,740
Divided by.

88
00:06:26,820 --> 00:06:27,600
The.

89
00:06:28,540 --> 00:06:29,320
The x.

90
00:06:29,350 --> 00:06:39,970
The x is the the step or how this small change of x that this rod will be cut it into it.

91
00:06:39,970 --> 00:06:43,980
And then we shift enter and we have error.

92
00:06:43,990 --> 00:06:45,040
What is.

93
00:06:46,590 --> 00:06:47,700
A line.

94
00:06:49,710 --> 00:06:50,400
Line.

95
00:06:50,410 --> 00:06:51,900
Linspace is.

96
00:06:52,260 --> 00:06:53,190
Oh, sorry.

97
00:06:54,150 --> 00:06:55,330
This has to go.

98
00:06:55,350 --> 00:06:56,330
Just this one.

99
00:06:56,340 --> 00:06:58,710
It's just a syntax error.

100
00:06:58,710 --> 00:07:07,110
And now we can see this vector, which is you can see it's start from oh point from zero and it will

101
00:07:07,110 --> 00:07:10,890
change to 0.1, 0.20.3.

102
00:07:10,890 --> 00:07:13,410
And of course it's just some numerical accuracy.

103
00:07:13,410 --> 00:07:16,770
It's quite high here, but it's not a problem.

104
00:07:16,770 --> 00:07:17,910
It's a simple problem.

105
00:07:17,910 --> 00:07:27,150
So it's maybe not so we don't have to care much about like if it's just too much accuracy regarding

106
00:07:27,150 --> 00:07:27,930
the X.

107
00:07:27,930 --> 00:07:32,820
So here we have it Now this is the the road.

108
00:07:32,820 --> 00:07:37,440
And what we will do now is we will do the same thing, but this time for time.

109
00:07:37,590 --> 00:07:49,020
So we will have TX equals some change in time, which is make it a bit small just to, to be, to,

110
00:07:49,050 --> 00:07:52,530
to like be careful about the convergence.

111
00:07:52,530 --> 00:07:55,690
So we just take the same thing here.

112
00:07:57,280 --> 00:07:59,650
And here it will be time.

113
00:08:00,280 --> 00:08:01,960
This will not be time.

114
00:08:01,960 --> 00:08:04,420
It will be the total simulation time.

115
00:08:05,240 --> 00:08:06,380
Over the.

116
00:08:07,580 --> 00:08:13,160
And this is going to be also the total simulation time and.

117
00:08:14,140 --> 00:08:14,830
We shifted.

118
00:08:15,830 --> 00:08:20,880
And now we see the vector of time, which is quite long.

119
00:08:20,900 --> 00:08:28,760
This is just means like zero, like points, points, points and till the end of the total simulation

120
00:08:28,760 --> 00:08:29,270
time.

121
00:08:29,270 --> 00:08:32,900
So it will keep changing, like it will keep increasing little by little.

122
00:08:32,900 --> 00:08:33,740
So.

123
00:08:33,740 --> 00:08:35,210
Okay, now we have.

124
00:08:35,980 --> 00:08:41,410
The length of the rod got well made.

125
00:08:41,410 --> 00:08:46,450
Small parts like kind of become numerical kind of mesh.

126
00:08:47,810 --> 00:08:54,110
And time is also being now like kind of well described.

127
00:08:54,110 --> 00:09:02,390
So what we need also what in the equation is of course, in the heat equation, we have to solve the

128
00:09:02,660 --> 00:09:12,980
we have the time, we have X and now you now you will be dependent on time and space, so T and X,

129
00:09:12,980 --> 00:09:15,290
So now we have to do it this way.

130
00:09:15,290 --> 00:09:18,560
So basically u equals.

131
00:09:19,690 --> 00:09:23,500
And this is also like if we consider this one.

132
00:09:24,390 --> 00:09:28,500
I will consider boundary condition.

133
00:09:28,500 --> 00:09:29,880
Just this one.

134
00:09:31,370 --> 00:09:34,820
And here we can consider.

135
00:09:36,080 --> 00:09:39,710
Or not in concert is actually the initial condition, which is you.

136
00:09:39,740 --> 00:09:45,310
We need to initialize the values of you numpy dot zeros.

137
00:09:46,750 --> 00:09:47,740
And.

138
00:09:49,290 --> 00:09:50,950
We give it dimension.

139
00:09:50,970 --> 00:09:54,030
The dimension is the length.

140
00:09:54,970 --> 00:10:00,400
And well the length of the space and linked with time.

141
00:10:00,550 --> 00:10:06,430
So we take the length of time, vector and length of.

142
00:10:07,200 --> 00:10:07,980
Space victim.

143
00:10:10,260 --> 00:10:12,060
And we put.

144
00:10:13,170 --> 00:10:13,500
Shift.

145
00:10:14,370 --> 00:10:19,560
So we see how our solution domain looks.

146
00:10:19,830 --> 00:10:24,630
And we have this is how many time steps and this is how many space steps.

147
00:10:24,630 --> 00:10:31,470
So we have 100 space steps and we have quite a lot like 100,000 time steps.

148
00:10:31,470 --> 00:10:37,860
Of course, this is a toy problem, so we don't really care about the values, but we need to really

149
00:10:37,860 --> 00:10:42,960
solve what we care about the numerical way of solving this problem.

150
00:10:42,960 --> 00:10:51,180
So anyway, you have this you if you want to look how you looks and we want to see how you looks, you

151
00:10:51,180 --> 00:10:53,400
can see that it's all zeros.

152
00:10:53,430 --> 00:11:02,130
We have a thousand, 100,000 sorry rows and we have 100 columns and it's all filled with zero.

153
00:11:02,250 --> 00:11:06,810
Now, the problem we have is, well, basically.

154
00:11:07,880 --> 00:11:11,810
A the rod will have a temperature.

155
00:11:12,860 --> 00:11:15,470
The road will have a temperature of.

156
00:11:21,170 --> 00:11:22,460
Just be like this.

157
00:11:22,820 --> 00:11:23,870
Start from.

158
00:11:27,610 --> 00:11:28,750
200.

159
00:11:30,160 --> 00:11:32,260
And then all of this.

160
00:11:32,990 --> 00:11:34,610
We'll go to 100.

161
00:11:34,610 --> 00:11:39,920
So the temperature will be a little bit high here and then we'll be 100 here.

162
00:11:39,920 --> 00:11:44,120
And in between, the temperature will be zero.

163
00:11:45,900 --> 00:11:48,450
Maybe it's better to use freezing.

164
00:11:49,600 --> 00:11:50,080
Yeah.

165
00:11:50,350 --> 00:11:52,720
So this is the initial condition now.

166
00:11:53,080 --> 00:11:58,900
What we didn't do so far is we didn't really well.

167
00:12:00,220 --> 00:12:00,880
Uh, sorry.

168
00:12:00,880 --> 00:12:01,230
This one?

169
00:12:01,240 --> 00:12:01,620
Yeah.

170
00:12:02,240 --> 00:12:03,380
We didn't.

171
00:12:04,540 --> 00:12:05,750
Now everything is zero.

172
00:12:05,770 --> 00:12:07,600
The whole road is zero.

173
00:12:07,840 --> 00:12:08,830
All the time.

174
00:12:09,130 --> 00:12:11,440
So we start from zero and everything.

175
00:12:11,440 --> 00:12:14,110
Now the values of the whole solution is zero.

176
00:12:14,260 --> 00:12:17,680
But now let's impose the boundary condition.

177
00:12:18,520 --> 00:12:26,260
Of course, if you want to change any value, for example, the first value zero zero, you want it

178
00:12:26,260 --> 00:12:27,670
to be 100.

179
00:12:27,790 --> 00:12:29,530
You can put it like this.

180
00:12:29,530 --> 00:12:35,620
And when you read the you now the become, we change this value to be 100.

181
00:12:35,620 --> 00:12:41,500
So basically this is the row and this is the column and this is how we refer to this array.

182
00:12:42,380 --> 00:12:43,100
NumPy array.

183
00:12:44,530 --> 00:12:52,000
Now to apply The boundary condition that we want is we want u.

184
00:12:52,000 --> 00:12:52,900
And.

185
00:12:53,940 --> 00:12:57,600
All the time have to be.

186
00:12:57,900 --> 00:13:07,830
And from this side, from the left side, it has to be the temperature of the left side, which is 100.

187
00:13:08,010 --> 00:13:10,080
So we will equal it.

188
00:13:12,000 --> 00:13:13,620
We will equal it twice.

189
00:13:13,620 --> 00:13:14,370
Not moving.

190
00:13:17,280 --> 00:13:17,790
Yep.

191
00:13:18,120 --> 00:13:20,970
Equal it with the left temperature.

192
00:13:20,970 --> 00:13:22,560
And you.

193
00:13:23,910 --> 00:13:26,880
Also all the time with.

194
00:13:27,450 --> 00:13:29,520
The last, not the last one.

195
00:13:29,520 --> 00:13:38,010
But the way Python works is either we tell them the length of the vector, which is a little bit dangerous.

196
00:13:38,220 --> 00:13:42,690
We we just put minus one which is related to the final point.

197
00:13:42,690 --> 00:13:48,840
So we put it minus equals and then we consider.

198
00:13:49,860 --> 00:13:52,110
The right temperature.

199
00:13:53,430 --> 00:13:55,350
We go all the way.

200
00:13:57,530 --> 00:14:01,220
Here and we paste it and then shift enter.

201
00:14:01,220 --> 00:14:04,620
And now let's see how it is.

202
00:14:04,650 --> 00:14:06,230
How does it look like?

203
00:14:06,740 --> 00:14:16,190
So we can see now it starts from the left, which is 100 degrees, and the right, which is will become

204
00:14:16,580 --> 00:14:19,340
a 200 degrees.

205
00:14:19,820 --> 00:14:32,420
So the last thing we need to do is we need to see how our solution will or how our actual problem description

206
00:14:32,420 --> 00:14:33,040
looks like.

207
00:14:33,050 --> 00:14:37,520
And here we will do a pie plot by.

208
00:14:38,950 --> 00:14:44,560
Plot dot plot and we will take.

209
00:14:45,600 --> 00:14:47,250
Not the T vector.

210
00:14:47,280 --> 00:14:48,690
The x vector.

211
00:14:50,590 --> 00:14:51,850
And put it here.

212
00:14:53,940 --> 00:14:57,540
We need to plot it with.

213
00:14:58,280 --> 00:15:04,490
0Y0 because we refer to the first time.

214
00:15:04,490 --> 00:15:07,670
This is, of course, a two dimensional array.

215
00:15:07,760 --> 00:15:20,030
And here we have the X and of course we have also need the A, the value of U and by plot.

216
00:15:20,880 --> 00:15:23,760
Dot y label.

217
00:15:25,140 --> 00:15:29,850
We can say them richer.

218
00:15:30,930 --> 00:15:31,830
And.

219
00:15:32,830 --> 00:15:33,910
Biplot.

220
00:15:35,250 --> 00:15:36,710
Dot x.

221
00:15:37,520 --> 00:15:38,390
Label.

222
00:15:39,370 --> 00:15:43,420
And we can say l x.

223
00:15:44,820 --> 00:15:47,460
And be a Pi plot.

224
00:15:47,940 --> 00:15:50,010
Just show the the thing.

225
00:15:50,930 --> 00:15:54,670
The show and we can have it and shift enter.

226
00:15:55,650 --> 00:15:56,700
By plot.

227
00:15:56,730 --> 00:15:57,410
Plot?

228
00:15:57,420 --> 00:15:58,110
Sorry.

229
00:15:59,080 --> 00:15:59,500
Yeah.

230
00:15:59,530 --> 00:15:59,980
This is where.

231
00:16:00,960 --> 00:16:10,110
So what do we have here is at the rod end of ten meter, we will have the temperature of 200 and the

232
00:16:10,110 --> 00:16:18,060
at zero, which is the rod end of the the left side of the rod, we will have the temperature of.

233
00:16:18,840 --> 00:16:19,740
A 100.

234
00:16:19,770 --> 00:16:21,900
The rest will be 100.

235
00:16:22,570 --> 00:16:28,330
So this way we define our solution space, which is the U.

236
00:16:28,630 --> 00:16:30,400
We define the boundary condition.

237
00:16:30,400 --> 00:16:36,550
We define the initial condition, and we are ready to actually solve it.

238
00:16:36,550 --> 00:16:41,410
And of course, later we just see how the solution will will be.
