# Using Manipulate[ ] with physical units

I'm a new user, and am trying to build a simple Boyle's law system in Mathematica. I want to include the units of the values, as I may need to perform some conversions later. If my quantities are a discrete list, they work fine. I cannot seem to get it to work for a slider. Can you help? I need this for work, and it's quite urgent. I've searched for a while before posting this question. Here's my code:

Manipulate[
Text@Style[
Grid[{
{Row[{"Total fill volume is ", totalVolume}]},
{Row[{"Delivery rate is ", deliveryRate}]},
{Row[{"Product duration is ",
duration[totalVolume, deliveryRate]}]},
{Row[{}]},
{Row[{"Initial pressure is ", initialPressureG}]},
{Row[{"Drop in pressure is ", pressureDrop, "%"}]}
}, Alignment -> Left]
]
,
{{totalVolume, Quantity[30, "ml"], "Total fill volume"},
Quantity[{30, 45, 60, 90}, "ml"]},
{{deliveryRate, Quantity[1, "ml/day"], "Delivery rate"},
Quantity[{0.5, 1, 2, 3}, "ml/day"]},
{initialPressureG, 0, 100},
{{pressureDrop, 40, "Pressure drop"}, 0, 100, 5}
]


Instead of initialPressureG being a slider from 0 to 100, I want it to be a slider from 0psi to 100psi. Am I doing something stupidly wrong?

• Namitha, welcome to mma.se . Please include the missing function duration in your post. – kglr Sep 25 '14 at 13:01
• why not just use {Row[{"Initial pressure is ", initialPressureG, " Psi"}]}? – kglr Sep 25 '14 at 13:33
• ... or, if you want to display lbf/(in)^2 instead of psi use QuantityForm[QuantityUnit@Quantity@"psi", "Abbreviation"] instead of " psi". If you wish, you can also change the control to {initialPressureG, QuantityMagnitude[Quantity[0, "psi"]], QuantityMagnitude[Quantity[100, "psi"]]} – kglr Sep 25 '14 at 13:41
• @kguler What does duration do? If I use your option of changing the control, if and when I want to extract the value of what the user sets on the slider, would it have the dimension "psi"? Or would I have to set that separately in a calculation? – Namitha Jassem Sep 27 '14 at 5:39
• Namitha, re duration, i meant that your posted code does not include the definition of the function duration; so your code does not evaluate when we copy/paste it into a notebook. – kglr Sep 27 '14 at 7:00

dur = Times;
Manipulate[
Text@Style[
Grid[{{Row[{"Total fill volume is ", totalVolume}]},
{Row[{"Delivery rate is ", deliveryRate}]},
{Row[{"Product duration is ", dur[totalVolume, deliveryRate]}]},
{Row[{}]}, {Row[{"Initial pressure is ", initialPressureG}]},
{Row[{"Drop in pressure is ", pressureDrop, "%"}]}}, Alignment -> Left]],
{{totalVolume, Quantity[30, "ml"], "Total fill volume"}, Quantity[{30, 45, 60, 90}, "ml"]},
{{deliveryRate, Quantity[1, "ml/day"], "Delivery rate"}, Quantity[{0.5, 1, 2, 3}, "ml/day"]},
{initialPressureG, Quantity[Range[0, 100, .01], "psi"], ControlType -> Manipulator},
{{pressureDrop, 40, "Pressure drop"}, 0, 100, 5}]


Note: Use your function duration instead of dur.

• Isn't using QuantityMagnitude[] the same as just using the numbers 0 and 100? Does it make a difference to use qM @ Quantity[0, "psi"]? – Namitha Jassem Sep 27 '14 at 8:05
• @NamithaJassem, exactly ... if you just need the "psi" label you don't need Quantity or qm@Quantity` in the control specification.. – kglr Sep 27 '14 at 8:13
• Namitha, please see the edited version. – kglr Sep 27 '14 at 8:31
• Genius. Thank you so much!! – Namitha Jassem Sep 28 '14 at 7:17