2

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?

Öskå
  • 8,587
  • 4
  • 30
  • 49
  • 2
    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 05:39
  • Hm. I was hoping that using Evaluate[] would fix the issue. It actually does assign the lbf/(in)^2 to initialPressureG but the slider then displays as this:
        `initialPressureG Manipulator[0,{0 lbf/in^2,1+0 lbf/in^2},AutoAction->False]`
    
    – Namitha Jassem Sep 27 '14 at 06:37
  • 1
    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 07:00
  • I posted an answer showing what I get when I make changes in your code along the lines suggested above. – kglr Sep 27 '14 at 07:22
  • Thank you @kguler! Yep, you're right, I forgot duration[] but it doesn't affect any calculations - only used for output. – Namitha Jassem Sep 27 '14 at 08:05

1 Answers1

1
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.

kglr
  • 394,356
  • 18
  • 477
  • 896