2
$\begingroup$

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?

$\endgroup$
8
  • 2
    $\begingroup$ Namitha, welcome to mma.se . Please include the missing function duration in your post. $\endgroup$
    – kglr
    Commented Sep 25, 2014 at 13:01
  • $\begingroup$ why not just use {Row[{"Initial pressure is ", initialPressureG, " Psi"}]}? $\endgroup$
    – kglr
    Commented Sep 25, 2014 at 13:33
  • $\begingroup$ ... 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"]]} $\endgroup$
    – kglr
    Commented Sep 25, 2014 at 13:41
  • $\begingroup$ @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? $\endgroup$ Commented Sep 27, 2014 at 5:39
  • 1
    $\begingroup$ 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. $\endgroup$
    – kglr
    Commented Sep 27, 2014 at 7:00

1 Answer 1

1
$\begingroup$
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}]

enter image description here

Note: Use your function duration instead of dur.

$\endgroup$
4
  • $\begingroup$ 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"]? $\endgroup$ Commented Sep 27, 2014 at 8:05
  • $\begingroup$ @NamithaJassem, exactly ... if you just need the "psi" label you don't need Quantity or qm@Quantity in the control specification.. $\endgroup$
    – kglr
    Commented Sep 27, 2014 at 8:13
  • $\begingroup$ Namitha, please see the edited version. $\endgroup$
    – kglr
    Commented Sep 27, 2014 at 8:31
  • $\begingroup$ Genius. Thank you so much!! $\endgroup$ Commented Sep 28, 2014 at 7:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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