# Where is the unit after a calculation?

I was playing with some of the new features, and when I type e.g.

Quantity[10, "ml"] + Quantity[250 - 100, "ml"]


I get

160 mL


as expected.

But when I want to solve the following equation

Solve[Quantity[x, "ml"] Quantity[5, "mol"] + Quantity[250 - x, "ml"] Quantity[7, "mol"] ==
Quantity[250, "ml"] Quantity[6, "mol"], x]


I get

{{x -> 125}}


without any unit. But x actually is in mL. So I'm wondering what I am getting wrong, i.e. why don't I get mL here?

thanks!

-

x is not in mL..it is just a pure number. Quantity[x, "ml"] is the 'thing' that is in mL.

To get what you want, you need to recast your Solve command as

Solve[x Quantity[5, "mol"] + (Quantity[250, "ml"] - x) Quantity[7,
"mol"] == Quantity[250, "ml"] Quantity[6, "mol"], x]


However, the result is a bit strange looking.

{{x -> Quantity[1/8000, ("Meters")^3]}}


It is, however, correct. Let's convert it to numerical form

Solve[
x Quantity[5, "mol"] + (Quantity[250, "ml"] - x) Quantity[7,
"mol"] == Quantity[250, "ml"] Quantity[6, "mol"], x] // N


gives

{{x -> Quantity[0.000125, ("Meters")^3]}}


Which looks right since 1 mL= 0.000001 m^3

How to force Mathematica to stick to mL, however, is another question.

Of course you could get back to mL by using UnitConvert. For example

UnitConvert[
x /. Solve[
x Quantity[5, "mol"] + (Quantity[250, "ml"] - x) Quantity[7,
"mol"] == Quantity[250, "ml"] Quantity[6, "mol"],
x] [[1]], "Milliliters"]


gives

Quantity[125, "Milliliters"]

-
Not strange at all! UnitConvert[Quantity[1/8000, ("Meters")^3], "Milliliters"] = 125 mL. – P. Fonseca Dec 6 '12 at 21:48
agreed. Perhaps I should have said 'unexpected' because one might like like to remain in Milliliters. – WalkingRandomly Dec 6 '12 at 21:54
Thanks! I think I have to get used to Quantity a little more. – Mockup Dungeon Dec 7 '12 at 9:34
{"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "url": "http://mathematica.stackexchange.com/questions/15869/where-is-the-unit-after-a-calculation", "fetch_time": 1469640036000000000, "content_mime_type": "text/html", "warc_filename": "crawl-data/CC-MAIN-2016-30/segments/1469257826916.34/warc/CC-MAIN-20160723071026-00115-ip-10-185-27-174.ec2.internal.warc.gz", "warc_record_offset": 161025721, "warc_record_length": 17522, "token_count": 605, "char_count": 1873, "score": 3.59375, "int_score": 4, "crawl": "CC-MAIN-2016-30", "snapshot_type": "latest", "language": "en", "language_score": 0.8706637620925903, "file_path": "/sailhome/yjruan/project/latent-lm/data/processed/finemath-4plus/finemath-4plus/train-00057-of-00064.parquet"}