Group Abstract Group Abstract

Message Boards Message Boards

0
|
1K Views
|
8 Replies
|
3 Total Likes
View groups...
Share
Share this post:

Issue with the output of units

Posted 2 months ago

POSTED BY: Ian Williams
8 Replies
Posted 2 months ago
POSTED BY: Eric Rimbey

You may try with a replacement rule for display purposes only:

Quantity[3, "Kilonewtons" "Meters"] /.
 Quantity[n_, "Kilonewtons" "Meters"] :> Row[{n, "kN"*"m"}]
POSTED BY: Gianluca Gorni
Posted 2 months ago

This isn't much of an answer, just a small clarification. Quantity does, in fact, hold the units argument, including the order in which you supply units. You can see this if you use FullForm. The display is being created as a special little display object in the front end. It's a bit like evaluating Red and seeing the little square. The actual result of evaluating Red is RGBColor[1, 0, 0], but what you see is a display object. Of course, none of that is helpful, because you probably don't want to look at raw Quantity expressions either.

I'm assuming that Mathematica is displaying units in some canonical order, and maybe standard units precede derived units. I'm guessing that you probably can change this by "pulling back the covers" and providing your own formatting code to make the boxes that represent Quantitys as display "objects". I don't know how to do that, but I've seen others do similar things. If you don't get an answer here, you might post (or search first) at the stack exchange for Mathematica: https://mathematica.stackexchange.com .

POSTED BY: Eric Rimbey
POSTED BY: Ian Williams

Thanks for the suggestion. But, as you say, this is suitable for display purposes only. The Head of the output expression is Row and cannot be used for calculation. Furthermore, I don't relish the prospect of having to apply a replacement rule whenever I use certain units.

POSTED BY: Ian Williams

Agreed. But it shouldn’t be necessary to need to drill down into the display object.

POSTED BY: Ian Williams

Yep. But, in my experience, kNm are the units most Engineers use for bending moments. There should be a simple way of preserving the unit input order in the output cell. And, arguably, preserving the input order should be the default behavior.

POSTED BY: Ian Williams

kN m or m kN is in fact the unit kJ or kiloJoule. If you demand the answers in kJ, there is no problem, and you are always in normal unit notation.

POSTED BY: Malcolm Woodruff
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard