1
$\begingroup$

The problem I expected Mathematica to solve rather easily is that of the calculus of a moment of inertia of a "c" section defined by the following Polygon:

sezione = 
  Polygon[{{-0.06, 0.09}, {0.10, 0.09}, {0.10, 0.07}, {-0.04, 
     0.07}, {-0.04, -0.07}, {0.1, -0.07}, {0.1, -0.09}, {-0.06, \
-0.09}}];
MomentOfInertia[sezione]
MomentOfInertia[sezione, RegionCentroid[sezione]]
RegionCentroid[sezione]
MomentOfInertia[sezione, {-0.00130435, 0}]

I expected the outputs to be the same! Instead they aren't at all as the first element of the matrix changes unexpectedly. Why is this? If I specify the coordinates of the center of mass it doesn't give the same answer! Also, I believe the last answer is the correct answer.

EDIT

These are my outputs:

{{0.0000991333, -9.*10^-7}, {-9.*10^-7, 0.000074011}}
{{0.0000991333, -9.*10^-7}, {-9.*10^-7, 0.000074011}}
{-0.00130435, 0.}
{{0.0000457467, -9.*10^-7}, {-9.*10^-7, 0.000074011}}

If one would rationalize the input (as suggested), you would get the following answer:

N[MomentOfInertia[Rationalize[sezione]]]

You would have the correct answer:

{{0.0000457467, 0.}, {0., 0.000023291}}

I believe this could be a bug. As it is self-evident that users replying to my question have different answers with the exact same code. My version is Mathematica 10.4 Student Edition.

$\endgroup$
  • $\begingroup$ Try removing the repeated point. $\endgroup$ – J. M. will be back soon Jul 22 '16 at 17:24
  • $\begingroup$ It is the same! I didn't have it firstly. @J.M. $\endgroup$ – Mirko Aveta Jul 22 '16 at 17:25
  • $\begingroup$ Really? It works if I remove either the first or the last point in my tests. $\endgroup$ – J. M. will be back soon Jul 22 '16 at 17:28
  • $\begingroup$ I've quit the Kernel and no, it doesn't work! @J.M. $\endgroup$ – Mirko Aveta Jul 22 '16 at 17:29
  • 1
    $\begingroup$ What version and OS are you on? Another possibility: try applying Rationalize[] to your points. $\endgroup$ – J. M. will be back soon Jul 22 '16 at 17:31
2
$\begingroup$

As pointed out by @J.M. using Rationalize will help (by avoiding round-off error).

But you've also put in a rounded number (-0.00130435) in your last statement that also contributes to differences. Here's a list of statements (and outputs) from Mathematica 10.4.1 (Windows 7):

sezione = 
  Polygon[{{-0.06, 0.09}, {0.10, 0.09}, {0.10, 0.07}, {-0.04, 0.07},
{-0.04, -0.07}, {0.1, -0.07}, {0.1, -0.09}, {-0.06, -0.09}}];

MomentOfInertia[sezione]
    (* {{0.00004574666666666663`,-1.6940658945086007`*^-21},
       {-1.6940658945086007`*^-21,0.000023291014492753617`}} *)
MomentOfInertia[sezione, RegionCentroid[sezione]]
    (* {{0.00004574666666666663`,-1.6940658945086007`*^-21},
       {-1.6940658945086007`*^-21,0.000023291014492753617`}} *)
RegionCentroid[sezione]
    (* {-0.0013043478260869653`,0.`} *)
MomentOfInertia[sezione, {-0.00130435, 0}]
    (* {{0.00004574666666666663`,-8.470329472543003`*^-22},
       {-8.470329472543003`*^-22,0.000023291014492753658`}} *)

rc = RegionCentroid[sezione]
MomentOfInertia[sezione, rc]
    (* {{0.00004574666666666663`,-1.6940658945086007`*^-21},
       {-1.6940658945086007`*^-21,0.000023291014492753617`}} *)


MomentOfInertia[Rationalize[sezione]]
    (* {{3431/75000000, 0}, {0, 40177/1725000000}} *)

N[MomentOfInertia[Rationalize[sezione]]]
    (* {{0.00004574666666666667`,0.`},{0.`,0.000023291014492753624`}} *)
$\endgroup$
  • $\begingroup$ Ok. I believe we are missing the point. If I run your code on my version of Mathematica I receive different answers as I've lastly written in the comments above. I suppose this is a error and it might have been corrected in your version. $\endgroup$ – Mirko Aveta Jul 23 '16 at 11:10
  • $\begingroup$ It would help others if you would edit your question and put in your version of Mathematica and the results you obtained as those can be missed if they are only in the comments. Also, doesn't obtaining 0.00074011 concern you if the correct answer is 0.000023291 ? (assuming the input precision is exact) $\endgroup$ – JimB Jul 23 '16 at 16:25
  • $\begingroup$ Ok. I'll edit my question. $\endgroup$ – Mirko Aveta Jul 23 '16 at 16:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.