I've run into a little problem, and I think in my research I've run into a dead end. I'm trying to perform some basic calculations with units, but Mathematica refuses to simplify the most basic commands. I saw that this person had the same issue (well, their problem had apparently a different origin), but the thread is over a year old and no one in the comments or answers was able to provide an answer. I was hoping some fresh eyes could have any idea.

I'm highlighting the inconsistencies in the picture below: Test 1

I was wondering why Mathematica would refuse to simplify the first expression, even though they clearly have compatible units. I started playing in Test 1 and 2 and clearly it wasn't a problem of the units themselves, but as we can see in the next picture

Test 2

using the ScientificForm command breaks Mathematica's brain and it can't give you a proper answer anymore. I tried 3 different ways, the first one using all variables with ScientificForm applied, then the same units, but applying ScientificForm to the result, and then finally the same values without SF, only this one gives a proper answer. It is extremely annoying that I can't just regularly save my variables in the form that is most convenient to use, instead I have to copy the result, input it through mathematically independently as a regular equation and then save it under a different name.

Does anyone know if there is any solution to this? Simpler "primitive" fixes that just circumvent the problem are also welcome.

Edit: Copyable code

JBS = 
   0.001 Quantity[1, "Meters" ("Seconds")^2]*Quantity[1, "Newtons"]];
JB = 0.001 Quantity[1, "Meters" ("Seconds")^2]*
   Quantity[1, "Newtons"];
mB = 1000 Quantity[1, "Grams"];
mBS = ScientificForm[1000 Quantity[1, "Grams"]];
b = 1 Quantity[1, (("Centimeters")^2)];
bS = ScientificForm[1 Quantity[1, (("Centimeters")^2)]];
{JBS + mBS bS, ScientificForm[JBS + mBS bS], JB + mB b}
  • $\begingroup$ Welcome to Mma.SE! start by taking the tour now. It helps us to help you when you write an excellent question. Here it’s considered helpful to share your code in a well-formatted form instead of images or links to external files, so we can quickly Copy&Paste your code, test it, and see the problem you are facing. Please help us to help you and edit your question accordingly. This question in Meta could be useful. $\endgroup$
    – rhermans
    Sep 20 at 13:39
  • 3
    $\begingroup$ What is cm^2 and how is it entered? Same thing for all of the units entered. Also, can you post copyable code, instead of the picture? $\endgroup$
    – rcollyer
    Sep 20 at 13:46
  • 3
    $\begingroup$ I see the problem now. I have two general comments. (1) I don't really understand why you don't put the magnitudes directly into Quantity, that is: Quantity[1000, "Grams"] instead of 1000 Quantity[1, "Grams"]. (2) ScientificForm is meant to be used when outputing/printing the numbers and not for storing your quantities. That is: use mBS = Quantity[1000, "Grams"]; when defining mBS, and then use ScientificForm[mBS] when you want to print the value. Therefore, remove all ScientificForm from your definitions and the code should work properly. $\endgroup$
    – Domen
    Sep 20 at 18:07
  • 1
    $\begingroup$ Thank you, yeah I figured if I removed all ScientificForms it would solve the problem, it was just convenient since I usually have to write a lot of results in between. It's not that I don't put the magnitude directly into Quantity, it's just what happens when I copy the code. I use it with the shortcut like in the pictures, I think the code looks a lot cleaner that way. I will keep in mind using ScientificForm only to display and not to store from now on. $\endgroup$ Sep 21 at 10:28
  • 1
    $\begingroup$ Regarding the input and clean code: have you ever tried evaluation in place? For example, you type in mB = Quantity[1000, "Grams"], then select the whole Quantity[...] expresion and click CTRL+SHIFT+Enter (or in the menu Evaluation > Evaluate in place). $\endgroup$
    – Domen
    Sep 21 at 11:17

Your Answer

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

Browse other questions tagged or ask your own question.