So now let's go ahead and let's implement these equations, so we have no end coupled equations and
it can be a bit tricky to really define the function.
So we as as previously we must define a function that basically is an array with all the right hand
sides of these equations.
So it will be after what we could call it.
And then as the arguments, we have to time and then the array, which is you in our case.
So when you goes with the index from zero to and minus one in Python language, and of course, we must
update now to you.
So we must write to you and you is something and then return.
You knew it, since this is a bit tricky.
Let me start with a more simple example.
So testing cell here, this is often quite useful if you don't really know how to proceed.
You just start with a simple example, and as I said, you is an error rate.
So let's just use some numbers, for example, the square numbers.
And then what we do is we generate you knew which I just call you here.
And first of all, we say it's given by MP dot zeros and the length is five.
So when you run this, we have now to erase you.
Or maybe let's let's do it like this.
Sorry for the confusion.
So let's do it like this.
You as this array and you new is an array of zeros.
So now we update you new starting from one, then going to minus one.
So this means we do not consider you zero in next.
So we leave out the very left element and we go to minus one, which is the last one.
But in the Python syntax, this one will be excluded.
So actually, we only go to here.
So in this particular example, we only considered these three entries and not the left one, not the
right one.
And this one is, are these three elements are given or are calculated in the following way you.
Starting from two going to the end, so we just write nothing minus two times.
You.
Going from one to minus one, so this would be exactly the same indices as here and then plus you starting
from the very first one.
So we're right nothing and going to minus two.
So this is exactly what is written down here.
So for every index, we basically shift a tier one upwards.
Here we keep the indices, here we shift downwards, you could say.
And so in this way, we have implemented these whole equations except for the very left and for the
very right.
So if I run this, we have now you knew, which basically is the the river tiff or the the second order
derivative.
So for left and right, it is zero.
And then since we have to find a tier of zeros and then here for the middle elements it is given by
justice critics, the equation and we have left out he and Delta X, which we won't just say is equal
to one.
OK, so now let's continue and apply this to our function.
So of course we need the aid.
But as I also said, we set it equal to one.
So we're right.
A is equal to one, the X is equal to one.
And now we must write something very similar to here.
So we write you new is equal to and p zeros.
And the length will be the length of you because we must make it universal.
We cannot just write down a number here.
And then you knew with these indices.
So basically, we can just copy this, I think.
Yeah.
So this will mean, except for the very first and the very last element, use this terms.
These terms here with the shifted index, with the shifted index along the other direction to you with
the same indices to express this discrete taste derivative.
And then we return.
You knew.
And now we have to account for this prefecture, so I could add it here.
But I can also just add it here.
It doesn't matter.
So I write a divided by D x square.
All right.
And now this gives me basically the right hand side of this equation, so it gives me this one.
And it's an array of and coupled equations.
So it's an yeah, it's just the array, basically this one here.
OK.
So now we have a equation and now we can go ahead and solve the system.
So the right solution is equal to integrate, dot, solve, underscore IVP function, then the times
T starts T and as is always the same as before and T start is zero and T and it takes something a bit
larger.
So I tested this before.
Let's take a thousand.
Then we use the starting conditions, so we just use zero you zero with it.
We must define now.
But first, let me write method is equal to our K 4.5.
And then since we want to have all the time steps we write T evaluate is equal to NPI total in space
to start comma, t and comma ten thousand one.
So now we go in steps of zero point one.
In this case, it's not the only thing left to do would be the starting conditions.
And by defining the starting conditions, we also define the size of the array of the whole array of
everything here.
So to size, I want to make it here 100 somewhere and is now or 1000 is now 1000 and u zero will be
basically in the beginning, just zeros.
So
like this?
And only on the left, we will change these values.
So basically, we could write you zero is equal to one.
You know, we can run this and now we can plodded.
So, for example, we can right now Pulte dots plot solution dots t comma solution thought to why?
And now we write, for example.
I don't know.
Let's take.
Let's take the middle coordinate.
So this would be 500.
So here we must specify now which of these elements we want.
So do we want you want?
Do we want you?
And do we want something in between?
And I take here 5000, which we can also write as size divided by two.
And I want to take it into three divisions so that we really have an index here and oh, we get basically
zero.
You know, maybe this is because the time was too small and because the size or the size was too large,
maybe to make the size a bit smaller?
OK, yeah, this is more like I wanted it to be.
So what we see here is on the x axis, the time and on the y axis.
The temperature
for whom you could say sell no more than
the number would be.
This one.
So we could right index is equal to size.
Divide it by two and then we can just write like this.
Yeah.
Temperature for cell number 50 and the time and you see in the beginning, the temperature is zero.
Just because we have basically specified sarin or something, I changed later on.
We have specified that all of the U-values would be zero, except for the very left one, which was
one.
And since we did not define any updates to the very left one, it will be one the whole time.
So it will be a constant heat bath with a temperature of one.
And it will heat the remaining sample.
And you see, after some time, the bar or the sample, which is one dimensional, will heat up.
And even in the middle, the cell number 50, which is exactly in the middle, will heat up after some
time and then it will increase.
So of course, we can now increase the time, the simulation time, and you see it will heat up to approximately
zero point five.
Let's see if we go to 10000.
Yeah, exactly, it will heat up pretty briefly until it is at zero point five.
This is because at the right point, we also do not update the function here.
So this means there is a constant heat, both with the temperature zero.
So when we look at the very middle after everything has relaxed after a very long time, the the temperature
in the middle will be just between the high and the low temperature, so it will exactly be zero point
five.
So maybe that's decreased is a bit more.
And let's let me show you another way to visualize this.
So for this, I will plot this whole thing in a density plots.
So let me show you how this works.
T lists Color X list.
This is something we did already.
Previously, we used to mesh predicament to basically define all the pairs of X y coordinates that we
will use now for the plot.
So we righthere solution dots T and then here I just write ENPI dots per inch size.
So this will be in the array counting from zero to size, which was one hundred in our case.
All right.
And then we writes Peel T Dot Contour F, and then we have T least comma x list.
And then the solution thought Y.
All right.
So now we can add Colaba peeled C dot Calabar.
And we can also, of course, at the labels, which in this case will be
here the time T and here it will, of course, now be oops, the coordinate.
Or you could also say the cell index.
Okay, so you see ad time equal to zero.
We have basically everywhere zeros.
Everything is blue here, which corresponds to zero, and only at this point we have something that
heats up where the temperature is held constant at one.
And since we don't update the left and the right end of the bar, this will always be one and this will
always be zero.
And since this is not a nice temperature gradient, according to the heat equation, after some time
where everything has relaxed, we get this nice homogeneous gradient.
And this is also why, after some time, exactly in the middle, the temperature will be zero point
five, which is exactly between one and zero at the left and and the right end.
So now we can, of course, go ahead and use some other starting parameters.
So I will just, yeah, basically copy this one.
And copy this one.
And also this one, and for the starting parameters, I will now use another starting condition where
I say also the right end of the bar should not be zero, but should be one.
Now if I run this, you see that the middle temperature will turn to one and the whole temperature of
the whole bar when we plotted at the beginning.
It will be at one and one at the left and right.
And so here at zero and 100 and everywhere else, it will be zero as we have to find it.
But then after some time, of course, the whole bar will have heated up.
So maybe here it's a bit better to just go to one thousand.
Or we could also go to maybe 2000.
Yeah, that's much better.
So you see here, everything remains cold, but then since we have here some heat bath and here some
heat bath, the whole sample will be heated up.
And this heating effect will increase over time.
And then at some point, everything will be hot and the temperature will be equal to one.