|
|
|
|
|
by gejjaxxita
4376 days ago
|
|
Say I had an array of masses and their velocities and I wanted to calculate the kinetic energy of each mass using the equation: E = 1/2 mv^2
With operator overloading: E = 0.5 * (m * v)**2
Without: E = (m.mult(v)).pow(2).times(0.5)
The operator overloaded example is Python (numpy) - the non-overloaded one is something I made up, but it's basically what it would need to look like.I think the first example is much closer to the maths. This is not some contrived example, if you have raw data and you're using mathematical equations to work out relationships you do this kind of thing all the time. |
|