So we start our numerical solution for the heat equation by actually this.
Well, Jupyter Notebook.
Will I like Jupyter Notebook?
Of course, because it's easy to see how the numbers are changing.
And so we start by just writing the name of the of the file.
And in our case, we can call it, well, heat.
It's Maine.
And now we have the file and we can press save just to make sure that the file is actually saved.
So starting with, well, our solution, it's all usual libraries because, uh, because we will write
everything by most of the things by ourselves.
So we first need to import.
We make it a little bit like zoom in, import numpy.
And from.
Of course, Matlab, the numpy is for math and from matplotlib or matrices to be more accurate.
Regarding the numpy.
NumPy arrays by plot.
To plot things.
And of course shift and enter.
So this means it got imported into the our system.
Now, the first thing is we need to set some variables that in the well, in the like describing our
system kind of or it is like what we call post-processing.
So the first thing is we need the length of the rod, let's say, to be ten.
And the reason I put a ten because I tested one meter, it's just it will diffuse too fast.
So we'll just put it ten and K equals 0.89 and.
Temp.
Or temperature left equals.
We can consider 100 degrees and temperature.
At.
Right?
Right.
Will be, let's say 200.
So you will have in balance one is or in the left, you have 100, and on the right you have 200.
So.
The total simulation time.
Total.
All time.
Our simulation time well equals ten and shifted.
So now we decide or we considered a rod one temperature, one part or one end of it will have 100 degrees,
the other end will have 200 degrees.
And um, we will later define the initial condition, which is the rod itself will have a temperature
of zero.
So what does it mean?
This is what we call boundary condition.
The boundary condition is.
At the right, it will be 200 degrees and the left will be 100 degrees.
So the X equals 0.1.
And of course, this is the value for aluminum and you can, of course, change it as you like.
I think it's a little bit high.
And yeah, just just put it wherever like for this thing you can put it any value one.
But of course we if you're simulating an actual material now took the number is just for aluminum but
if you simulate any an actual material you have to check the actual the material value itself.
So we consider that we have a ten meter rod or like, Yeah, a rod and we have 0.1, which is the so
you will have a oh point like ten centimeter basically.
Yeah.
Ten centimeter for every A this is the mesh you will calculate.
So.
What we will have is we will have the actual.
Yeah, this one.
We will have the actual road goes like this and here we will have 200 degrees.
And here you will have um, just let me look at the left.
100.
Yeah, it's correct.
100 is left and.
And this is basically our road.
And then what we will do is here we have a discretized.
So every we will cut this road into small, small, small parts.
And this part will be a 0.1 meter, of course.
And of course the road is ten meter.
Of course, this is just dummy value, just whatever it is.
But and if you want to really, of course, solve this problem, you have to be careful about the physics.
The physics values.
So here the X equals 0.1.
Now.
What we need is we need the vector.
Vector.
Equals the x vector.
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
centimeter.
So we need to cut it.
So we say numpy, we will make a basically a list of values or, or more like it's a numpy array of
these values that will increase little by little.
So we have a numpy line.
Space.
It will start from zero until the length.
The length of the rod with an interval of.
A length of the rod.
Divided by.
The.
The x.
The x is the the step or how this small change of x that this rod will be cut it into it.
And then we shift enter and we have error.
What is.
A line.
Line.
Linspace is.
Oh, sorry.
This has to go.
Just this one.
It's just a syntax error.
And now we can see this vector, which is you can see it's start from oh point from zero and it will
change to 0.1, 0.20.3.
And of course it's just some numerical accuracy.
It's quite high here, but it's not a problem.
It's a simple problem.
So it's maybe not so we don't have to care much about like if it's just too much accuracy regarding
the X.
So here we have it Now this is the the road.
And what we will do now is we will do the same thing, but this time for time.
So we will have TX equals some change in time, which is make it a bit small just to, to be, to,
to like be careful about the convergence.
So we just take the same thing here.
And here it will be time.
This will not be time.
It will be the total simulation time.
Over the.
And this is going to be also the total simulation time and.
We shifted.
And now we see the vector of time, which is quite long.
This is just means like zero, like points, points, points and till the end of the total simulation
time.
So it will keep changing, like it will keep increasing little by little.
So.
Okay, now we have.
The length of the rod got well made.
Small parts like kind of become numerical kind of mesh.
And time is also being now like kind of well described.
So what we need also what in the equation is of course, in the heat equation, we have to solve the
we have the time, we have X and now you now you will be dependent on time and space, so T and X,
So now we have to do it this way.
So basically u equals.
And this is also like if we consider this one.
I will consider boundary condition.
Just this one.
And here we can consider.
Or not in concert is actually the initial condition, which is you.
We need to initialize the values of you numpy dot zeros.
And.
We give it dimension.
The dimension is the length.
And well the length of the space and linked with time.
So we take the length of time, vector and length of.
Space victim.
And we put.
Shift.
So we see how our solution domain looks.
And we have this is how many time steps and this is how many space steps.
So we have 100 space steps and we have quite a lot like 100,000 time steps.
Of course, this is a toy problem, so we don't really care about the values, but we need to really
solve what we care about the numerical way of solving this problem.
So anyway, you have this you if you want to look how you looks and we want to see how you looks, you
can see that it's all zeros.
We have a thousand, 100,000 sorry rows and we have 100 columns and it's all filled with zero.
Now, the problem we have is, well, basically.
A the rod will have a temperature.
The road will have a temperature of.
Just be like this.
Start from.
200.
And then all of this.
We'll go to 100.
So the temperature will be a little bit high here and then we'll be 100 here.
And in between, the temperature will be zero.
Maybe it's better to use freezing.
Yeah.
So this is the initial condition now.
What we didn't do so far is we didn't really well.
Uh, sorry.
This one?
Yeah.
We didn't.
Now everything is zero.
The whole road is zero.
All the time.
So we start from zero and everything.
Now the values of the whole solution is zero.
But now let's impose the boundary condition.
Of course, if you want to change any value, for example, the first value zero zero, you want it
to be 100.
You can put it like this.
And when you read the you now the become, we change this value to be 100.
So basically this is the row and this is the column and this is how we refer to this array.
NumPy array.
Now to apply The boundary condition that we want is we want u.
And.
All the time have to be.
And from this side, from the left side, it has to be the temperature of the left side, which is 100.
So we will equal it.
We will equal it twice.
Not moving.
Yep.
Equal it with the left temperature.
And you.
Also all the time with.
The last, not the last one.
But the way Python works is either we tell them the length of the vector, which is a little bit dangerous.
We we just put minus one which is related to the final point.
So we put it minus equals and then we consider.
The right temperature.
We go all the way.
Here and we paste it and then shift enter.
And now let's see how it is.
How does it look like?
So we can see now it starts from the left, which is 100 degrees, and the right, which is will become
a 200 degrees.
So the last thing we need to do is we need to see how our solution will or how our actual problem description
looks like.
And here we will do a pie plot by.
Plot dot plot and we will take.
Not the T vector.
The x vector.
And put it here.
We need to plot it with.
0Y0 because we refer to the first time.
This is, of course, a two dimensional array.
And here we have the X and of course we have also need the A, the value of U and by plot.
Dot y label.
We can say them richer.
And.
Biplot.
Dot x.
Label.
And we can say l x.
And be a Pi plot.
Just show the the thing.
The show and we can have it and shift enter.
By plot.
Plot?
Sorry.
Yeah.
This is where.
So what do we have here is at the rod end of ten meter, we will have the temperature of 200 and the
at zero, which is the rod end of the the left side of the rod, we will have the temperature of.
A 100.
The rest will be 100.
So this way we define our solution space, which is the U.
We define the boundary condition.
We define the initial condition, and we are ready to actually solve it.
And of course, later we just see how the solution will will be.