Repository: sympy/sympy
Pull request: Improves the docstring of rigid body 
<!-- Your title above should be a short description of what
was changed. Do not include the issue number in the title. -->

#### References to other Issues or PRs
<!-- If this pull request fixes an issue, write "Fixes #NNNN" in that exact
format, e.g. "Fixes #1234" (see
https://tinyurl.com/auto-closing for more information). Also, please
write a comment on that issue linking back to this pull request once it is
open. -->
Fixes #24451 

#### Brief description of what is fixed or changed


#### Other comments


#### Release Notes

<!-- Write the release notes for this release below between the BEGIN and END
statements. The basic format is a bulleted list with the name of the subpackage
and the release note for this PR. For example:

* solvers
  * Added a new solver for logarithmic equations.

* functions
  * Fixed a bug with log of integers.

or if no release note(s) should be included use:

NO ENTRY

See https://github.com/sympy/sympy/wiki/Writing-Release-Notes for more
information on how to write release notes. The bot will check your release
notes automatically to see if they are formatted correctly. -->

<!-- BEGIN RELEASE NOTES -->
NO ENTRY 
<!-- END RELEASE NOTES -->


Problem statement:
sympy.physics.mechanics // RigidBody
I looked at the 'explanations' of RigidBody, using _help(me.RigidBody)._

For the kinetic energy I saw this:

_'T = 1/2 (I omega^2 + m v^2)'_

Should it not be:

T = 1/2 ( **(** I omega **)**^2 + m v^2 )

A **very minor** point, but since I saw it, I wanted to point it out.

Hints from issue discussion:
`T = rotational_KE + translational_KE`
where `rotational_KE = 1/2(I ω^2)`
and `translational_KE  =  1/2(m v^2)`
Hence , `T  = 1/2(I ω^2 + m v^2 )`
So , It was mentioned [right](https://github.com/sympy/sympy/blob/master/sympy/physics/mechanics/rigidbody.py#L235).
Are you sure?
I is a 3 x 3 matrix
omega is a vector, hence omega^2 = dot(omega, omega) is a scalar.
Hence, I omega^2 is a 3 x 3 matrix.

So, are you not adding a 3 x 3 matrix and the scalar m v^2 ?

Like I wrote, it is a small issue, only two parenthesis are missing.

On Sat 31. Dec 2022 at 08:26 ABHISHEK PATIDAR ***@***.***>
wrote:

> T = rotational_KE + translational_KE
> where rotational_KE = 1/2(I ω^2)
> and translational_KE = 1/2(m v^2)
> Hence , T = 1/2(I ω^2 + m v^2 )
> So , It was mentioned right
> <https://github.com/sympy/sympy/blob/master/sympy/physics/mechanics/rigidbody.py#L235>
> .
>
> —
> Reply to this email directly, view it on GitHub
> <https://github.com/sympy/sympy/issues/24451#issuecomment-1368178298>, or
> unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AT5MQURO2K772FSSPI3TK7LWP7N3PANCNFSM6AAAAAATNMJNW4>
> .
> You are receiving this because you authored the thread.Message ID:
> ***@***.***>
>
-- 
Best regards,

Peter Stahlecker

The moment of inertia is a tensor because it behaves both as a scalar and a vector, `rotational_KE = 1/2(I ω^2)` is also scalar quantity because it does not have a direction associated with it. It is simply a measure of the energy that an object possesses due to its rotational motion.
We can check how `rotational_KE = 1/2(I ω^2)` cames [here](https://farside.ph.utexas.edu/teaching/336k/Newton/node65.html)
Also we can check through dimensinal analysis of `1/2(I ω^2)` and `1/2(m v^2)` both are [ML^2T^(-2)]
Naturally I is a tensor, but does this mean it behaves like a vector *and*
a scalar - whatever this is supposed to mean?
In my opinion, I * omega^2 is not a scalar, (I * omega)^2 is a scalar -
both times interpreting vector^2 as the inner product of the vector with
itself.

The dimensional analysis is only a necessary condition for a formula to be
correct, certainly not a sufficient one.

I think, my *very* small point is not worth of further discussion.

On Sat 31. Dec 2022 at 09:43 ABHISHEK PATIDAR ***@***.***>
wrote:

> The moment of inertia is a tensor because it behaves both as a scalar and
> a vector, rotational_KE = 1/2(I ω^2) is also scalar quantity because it
> does not have a direction associated with it. It is simply a measure of the
> energy that an object possesses due to its rotational motion.
> Also we can check through dimensinal analysis of 1/2(I ω^2) and 1/2(m v^2)
> both are [ML^2T^(-2)]
>
> —
> Reply to this email directly, view it on GitHub
> <https://github.com/sympy/sympy/issues/24451#issuecomment-1368185902>, or
> unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AT5MQUVXJGDLM3KL7YOHBRLWP7W2DANCNFSM6AAAAAATNMJNW4>
> .
> You are receiving this because you authored the thread.Message ID:
> ***@***.***>
>
-- 
Best regards,

Peter Stahlecker

In a vector/matrix notation, it should be `omega.I.omega`, just like for the translational kinetic energy `v.m.v`. 
Then when the matrix `I` is just the identity matrix times a scalar the equation simplifies to the one given. I agree that this is somewhat of a sloppy notation, since this condition is certainly not always true, so your concern is correct, however, the suggested correction is incorrect. 
Personally I prefer a tensor with einstein summation convention notation:
`T = 1/2 (I_ij.omega^i.omega^j + m_kl.v^k.v^l)`
but this is often not used in text book equations (because it requires somewhat of a deeper understanding). It does mean that we are not relient on the order of the symbols that are multiplied and it immediately tells us that I and m transform in the opposite way w.r.t. omega and v respectively under a coordinate transformation.
I think, my suggested correction is correct, assuming vector^2 is
considered the inner product of vector with itself.

On Sat 31. Dec 2022 at 10:59 ThePauliPrinciple ***@***.***>
wrote:

> In a vector/matrix notation, it should be omega.I.omega, just like for
> the translational kinetic energy v.m.v.
> Then when the matrix I is just the identity matrix times a scalar the
> equation simplifies to the one given. I agree that this is somewhat of a
> sloppy notation, since this condition is certainly not always true, so your
> concern is correct, however, the suggested correction is incorrect.
> Personally I prefer a tensor with einstein summation convention notation:
> T = 1/2 (I_ij.omega^i.omega^j + m_kl.v^k.v^l)
> but this is often not used in text book equations (because it requires
> somewhat of a deeper understanding). It does mean that we are not relient
> on the order of the symbols that are multiplied and it immediately tells us
> that I and m transform in the opposite way w.r.t. omega and v respectively
> under a coordinate transformation.
>
> —
> Reply to this email directly, view it on GitHub
> <https://github.com/sympy/sympy/issues/24451#issuecomment-1368193814>, or
> unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AT5MQURTQYMJQE3MWQPB6SDWP77XPANCNFSM6AAAAAATNMJNW4>
> .
> You are receiving this because you authored the thread.Message ID:
> ***@***.***>
>
-- 
Best regards,

Peter Stahlecker

The equation for translational velocity is exactly the same, so then according to your argument the translational energy should be `(m.v)^2`
No, it is correct as given.


On Sat 31. Dec 2022 at 11:05, ThePauliPrinciple ***@***.***>
wrote:

> The equation for translational velocity is exactly the same, so then
> according to your argument the translational energy should be (m.v)^2
>
> —
> Reply to this email directly, view it on GitHub
> <https://github.com/sympy/sympy/issues/24451#issuecomment-1368194631>, or
> unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AT5MQUUZYYESOZFMREAA6ZTWQAAP3ANCNFSM6AAAAAATNMJNW4>
> .
> You are receiving this because you authored the thread.Message ID:
> ***@***.***>
>
-- 
Best regards,

Peter Stahlecker

I was wrong, the rotational energy is:

` 0.5 * inner_product(I*omega, omega) = 0.5 * dot(I*omega, omega)`
If this is the same as I * omega^2, then all is fine.
Yes, the same is meant. Using squares is mathematically not the nicest way to write it, as $\mathbf{v}$ and $\mathbf{\omega}$ are in fact vectors. However as you've pointed out, this is probably not worth further discussion, so I'll close this issue.

P.S. Planning to work on rewriting some of the mechanics, so maybe I'll change it to $\mathbf{v}^T M \mathbf{v} + \mathbf{\omega}^T I \mathbf{\omega}$ or $M \mathbf{v} \cdot \mathbf{v} + I \mathbf{\omega} \cdot \mathbf{\omega}$.

Commit message: fixes # 24451

Patch to review:
diff --git a/sympy/physics/mechanics/particle.py b/sympy/physics/mechanics/particle.py
index d8db1942c40b..6474ac7aad32 100644
--- a/sympy/physics/mechanics/particle.py
+++ b/sympy/physics/mechanics/particle.py
@@ -124,7 +124,7 @@ def angular_momentum(self, point, frame):
         The angular momentum H, about some point O of a particle, P, is given
         by:
 
-        H = r x m * v
+        `H = cross(r, m) * v`
 
         where r is the position vector from point O to the particle P, m is
         the mass of the particle, and v is the velocity of the particle in
@@ -167,7 +167,7 @@ def kinetic_energy(self, frame):
 
         The kinetic energy, T, of a particle, P, is given by
 
-        'T = 1/2 m v^2'
+        `T = 1/2 (dot(m * v, v))`
 
         where m is the mass of particle P, and v is the velocity of the
         particle in the supplied ReferenceFrame.
diff --git a/sympy/physics/mechanics/rigidbody.py b/sympy/physics/mechanics/rigidbody.py
index 59ef489e7dc6..496d182fa344 100644
--- a/sympy/physics/mechanics/rigidbody.py
+++ b/sympy/physics/mechanics/rigidbody.py
@@ -182,7 +182,7 @@ def angular_momentum(self, point, frame):
         The angular momentum H of a rigid body B about some point O in a frame
         N is given by:
 
-            H = I . w + r x Mv
+            `H = dot(I, w) + cross(r, M) * v`
 
         where I is the central inertia dyadic of B, w is the angular velocity
         of body B in the frame, N, r is the position vector from point O to the
@@ -232,7 +232,7 @@ def kinetic_energy(self, frame):
 
         The kinetic energy, T, of a rigid body, B, is given by
 
-        'T = 1/2 (I omega^2 + m v^2)'
+        `T = 1/2 * (dot(dot(I, w), w) + dot(m * v, v))`
 
         where I and m are the central inertia dyadic and mass of rigid body B,
         respectively, omega is the body's angular velocity and v is the


Code review comments:
diff_hunk: @@ -182,7 +182,7 @@ def angular_momentum(self, point, frame):
         The angular momentum H of a rigid body B about some point O in a frame
         N is given by:
 
-            H = I . w + r x Mv
+            `H = dot(I, w) + cross(r, M) * v`
path: sympy/physics/mechanics/rigidbody.py
text: @user1:
Should it not be `cross(r, Mv)`? I think cross products are only defined on vectors.

@author:
Sorry by mistake, I corrected it