OK, this lecture is referring to calculational sensor of mass, for example, suppose we want you formulated
as a as an optimization problem and the input data of the problem is as follows.
So, um, we want to find out the center of mass of a given set of objects which their location and
their mass are known.
And we want to find out what is the X and Y coordinates of the center of mass.
OK, so based on the formula, we know that the X of the center of mass is calculated using this Formula
X multiplied by the mass of an object.
I do the summation of our eye divided by, um, summation of all masses.
The same formula is for uh, applies for the, uh, y coordinate.
OK, so let's have a look at the.
Python code for this purpose.
OK, so you can see here that, um, at the beginning, as usual, we have to import all the required
packages here.
We do need to import Puyo Modot environment, uh, import everything.
Import Mathlouthi that's pipelined as pretty important vampi as ENPI and import random.
OK, um, we define an abstract model, uh and is representing the number of objects.
I specify the default value equal to 15, but you can easily change that in order to be able to change
that.
You can define defined as immutable parameter and then you have to define the set set of objects.
Um, if you need, uh, the, um, the location and also the masses of the objects can be specified
as the input parameters.
OK, but, um, you can define them as some random numbers.
So, um, you do need to, uh, specify them.
So X location, Y location, um, are the locations of the objects and the mass is already, uh, specify
the mass of each object and you initialize these parameters using the defined, uh, function so the
interval function will give random coordinates to X and Y and also the uh interval M is, um, giving
you some random masses to your objects, but you can also specify them in a file or something like that.
And also there are two decision variables, X and Y, the center of mass of the overall objects.
And since we are trying to find them in, um, uh, since we already specified, uh, X and Y locations
between zero and one, then the center of mass will be somewhere between zero and one.
OK, so I define them as valuable non-negative negative ones and I initialized the X and Y and using
this formula.
So initialize some uh, some constants.
OK, and then uh, we do need to write down two constraints.
One for X, one for Y, X is calculated using this formula, it's equal to and summation of X location
multiplied by their mass through the summation over the all the eyes in model and model.
I divide it by uh sum of all masses in the system.
The same concept holds for Y and uh, you have to define some constraint for that to be calculated.
Um, then, um, the objective function is the important part here.
So um, actually in this problem we don't have any specific objective function, we just have some constraints
that should be satisfied.
So you can simply specify X or Y as your objective function and you specify the sense as maximization
or minimization.
It doesn't matter because you want to.
And there is only one unique solution for that.
Uh, and there's nothing to maximize or optimize.
OK, so then you will have to, um, use some solver.
So since it's a linear programming, it's better to use pick as the solver.
And then and initially I have to specify the default value of the objects.
The number of objects is 15, but you can definitely change that.
You can say it's five or seven or anything at all.
You can leave it as it is it equal to fifteen and then ask, uh, more to solve it for you.
And finally, you can plot the results.
So let's run the code one by one tab.
OK, this one is run successfully, but this one.
Mm hmm.
This is also done, uh, the final one.
So you can see here that, uh, the there are five objects, um, randomly generated here.
Uh.
So, um.
You can see them here, and if I change the numbers, let's say it's, um, six.
OK, so I run this model again.
I calculated.
So there are six objects here.
One of them is very small.
So, um, let's hear one of them is here, here, here, here, here and here.
OK, so for six objects, the location of Center of Mass is found.
You can also print their values.
So XLF Center of Mass is.
I found, um, using the formula, so it's here, actually.
Hmm.
So, uh, this is the value of the center of mass.
You can also print it if you want.
Uh, and this is the this is it for this example.
Thank you very much.