So now let's get to the numerical results.
And since we want to compare this with the analytical results, let's first calculate the energy corresponding
to this term.
So this will be two of a five oops.
Sorry typo.
Two over five times.
I'm.
Times Radius Square.
And then because it's the energy, we also have to multiply with one half and all mega square.
So the result will be zero point two and this will be something we are now trying to restore using numerical
methods.
So here we once again will need something like a number of points.
And the idea that I'm using here is I'm going to create basically a cube consisting out of equidistant
points.
And then I'm going to check if the points that describe the cube are inside the sphere are nuts.
And if they are not inside the sphere, then they will be dropped.
And only if they are inside a sphere, they will be considered and will contribute to the integral.
So here you have to think a bit in advance and think of a reasonable approach.
So of course, you could try to do it in a similar way, as we did for the line where we have created
some list or some array of points with these explicit commands.
And this is probably possible, but it's much faster and much easier to just to use some loops.
So considering loops is sometimes considered bad fashion, this is because using loops can be very,
very slow.
But I think here it's totally reasonable because the whole calculation will not take such a long time
anyway.
And also, even if we would just work with arrays, we would still have to check.
Every element wants to see if the element is inside the sphere.
Not so.
I think it's totally fine to go ahead with loops.
So what we are going to need first is a MBTI or an empty coordinate list.
So this is where we will store our coordinates.
So basically, we will create a list or an array as we did before by using ample little space.
But this time we will not use line space, but we will go through loops and add the points manually,
basically.
So we are going to loop and you could use different type of loops, but I'm going to use here a for
loop for X.
And now we must provide an array or a list for the values over which we want to.
Loops are right for X and MP Lyn Space and I go from minus R to R, which is actually the capital R
here.
The actual radius.
And now I have to provide how many points we want to use, so I use these no points, of course.
And then we do something here, but I don't only want to loop over the X coordinates.
I also want to loop over the Y coordinates, which have the same limits and also over the Z coordinates,
which also have the same limits.
And now we must use an if statement.
So if here is not a condition, the condition will be if the if the point is inside the sphere or not,
we can check this by writing and p dot within towards the North.
So basically the length of the vector x y z.
So this would be something like, yeah, square root of x squared plus y square to square.
So it's the distance of this point that we are currently considering in the loop with respect to the
center of the sphere.
And if this one is smaller or equal to the radius of the sphere down, it's inside and this will be
good because then we are going to consider this point.
So now we are going to write what happens then and what happens is we are adding this point to the coordinate
list by writing quote list dot append and we are adding the point X, Y and Z.
So let me run this, but actually both of these lines.
And let me look at the output code list is a list of three coordinates.
So X, Y Z and all of these points are inside of the sphere.
So there are many of these points.
So this is, of course, not the only thing that we want to have.
I would say we would also add a counter to see how many points do we have because we will need this
to calculate the total mass of the object later on.
And so every time this is true, we increase the counter by one.
And then also we will look at the actual contribution to the integral.
So the contribution will be
will be added up every time this is true.
So we add up, so we increase it basically contribution as a contribution plus and now we are basically
adding up the value our square.
But please don't be confused here.
This is again, this are here, which is the distance of the point that we are considering to the z
axis.
So this is really important.
And P Dodds, Lynn Arc Dot know.
Of X y coma zero.
Because when you see X, this is our rotation axis.
Then the distance will just be square root of x squared plus y square and the Z component doesn't play
a role at all.
And the equation we had are square, so we right here also squared.
So here is oh yeah, like this.
Now the arrows gone.
And just to comment, this one here is actually just for plotting.
It's not really needed.
And of course, the same thing goes for this command here.
So if you don't want to plot anything, then you don't need these two commands.
And actually, it's pretty good to actually not use them because they are the most demanding things
because it will always append these points to the list.
But here we want to have a nice and beautiful result.
So of course, I'm going to save them and I'm going to use them to plot the sphere later on so we can
look at our results counter out of all the thirty times, thirty times.
Thirty points, which are twenty seven thousand twelve thousand seven hundred twelve, are inside the
sphere.
And what I want to do next is I want to generate the coordinates list for the plot, and maybe you remember
this from the crash course.
We do not need to have the syntax as we have it right now, where we have for every point such a bracket
of X, Y and Z.
But we must have three individual arrays corresponding to all the X coordinates, all the Y coordinates
and all the Z coordinates.
So we have to restructure this array and we can do this by writing NP Dot transpose.
So this leaves the data the same, but just reorder them and changes the brackets.
So basically, if you think of it as a matrix, it transposes the matrix.
So you see, now we have updated this, so we have overwritten the old coordinates list.
And now the coordinates list looks like this.
We have now a three individual arrays in this area.
And here we have all the X coordinates.
Here we have all the Y coordinates and here we have all the Z coordinates.
So we can, for example, write this and then this will just be the array of all the X coordinates.
And this is actually exactly what we are going to need next.
We are going to make a three day plot by writing pelted ot axes.
And as always, when we do three plots, we have to first enable the 3D option and we have to give it
a name Pulte 3D.
And now we can use this to make the plots.
So we writes Pulte 3D.
Can I use your eyes, get a 3D plot?
Now we must provide the three individual lists x coordinate, y coordinate and do z coordinate.
And I think this should work already.
Yeah, so here is our sphere.
So of course, we can now add labels for this.
I will scroll up because we have done it already so we can just copy the code from here, for example.
So we go here and we add to the coordinates, which in this case will be the actual Z coordinate.
So like this, and since this looks like just blue blob, I want to make the individual points a bit
smaller, which you can do by writing as is equal to some number.
Oh yeah, that looks better.
Or maybe even smaller.
No, I wanted zero for one.
Yes.
This looks really good.
So you see, now we started from an array or basically we looped over a cube.
And we have considered only the points that are inside the sphere, whose radius is smaller than the
radius of the sphere.
And so all of the points that we are considering are these that are plotted here.
And the contribution is already added up.
We have added up always the distance to the Z X squared, which is exactly what we need for the equation
because the equation was, um, let me scroll up.
We have this in the very beginning.
I think, yeah, here it is.
So the equation was the rotational energy is I of a two omega square with IBM, and this is the contribution
that we have just calculated, which means we have to now multiply this with the total mass and we have
to then, you know, also consider these other terms for the rotational energy.
So let's scroll down and do it.
So as I just said, what we have to do is we have to multiply with the mass.
And for this, we will use the total mass divided by the number of points that we have considered and
then we have 40.
You have to have the contribution.
So this would be the eye, but simply want to have the energy to kinetic energy.
We have to divide by two and have to multiply by omega square.
And the result is 0.1 99, something which is basically.
What we have from the analytical result, which was so difficult and so long to calculate, and here
it was actually pretty simple, we just had to use three four loops to loop over a cube.
And then we had to think about the condition, which was just a radius condition.
And then we just add up the contributions and in the end normalized the contribution to get the correct
results.