Mathematica - 使用Manipulate []和物理单位

时间:2014-09-25 08:35:02

标签: wolfram-mathematica units-of-measurement

我是新用户,我正在尝试在Mathematica中建立一个简单的Boyle法律系统。我想要包含值的单位,因为我可能需要稍后执行一些转换。如果我的数量是一个离散的列表,它们工作正常。我似乎无法让它适用于滑块。

在发布此问题之前,我已经搜索了一段时间。这是我的代码:

    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}
     ]

而不是initialPressureG是从0到100的滑块,我希望它是一个从0psi到100psi的滑块。我做了一些愚蠢的错误吗?

1 个答案:

答案 0 :(得分:0)

一种可能的解决方案是将滑块值保持为纯数字,以便分别转换为完整数量。例如:

Manipulate[DynamicModule[{valueWithQuantity = Quantity[value, "A"]},
  valueWithQuantity],
  {value, 0, 100}
]

此方法也可以在您的代码中使用

Manipulate[
 DynamicModule[{pressureDrop = Quantity[pD, "psi"]},
  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},
 {{pD, 40, "Pressure Drop"}, 0, 100, 5}
 ]

你得到了你的期望。