Group Abstract Group Abstract

Message Boards Message Boards

0
|
7.9K Views
|
6 Replies
|
3 Total Likes
View groups...
Share
Share this post:

Add units to variables inside a Manipulate expression?

Posted 6 years ago
6 Replies

This was very helpful! I think my issues were incorrect Quantity syntax and the added complication of not defining my function before using Manipulate (I've attached a notebook file where I did this wrong). I've also attached the notebook file that gives me what I wanted based on your example. I defined some of the parameters outside of the Manipulate expression instead of putting them in as unvarying quantities as you did, but this seems to also work. Do you see any potential problem with this method or are they equivalent?

I was having trouble with your definition of gravity, so I just replaced it with the internal definition of the physical constant. The manipulate appears to work as intended.

gamma = ChemicalData["Water", "SurfaceTension"];
mu = ChemicalData["Water", "Viscosity"];
rho = ChemicalData["Water", "Density"];
g = Quantity["StandardAccelerationOfGravity"];
darcyEqn[d_, c_, eps_, Rb_, L_, theta_, 
  phi_] := ((Pi (d/2)^2 c eps^3 Rb^2)/((1 - 
         eps)^2 mu)) (((3 (1 - eps) gamma Cos[theta])/(eps L Rb)) + 
    g rho Sin[phi])
Manipulate[
 UnitConvert[
  darcyEqn[d Quantity[1, "Millimeters"], c, eps, 
   Rb Quantity[1, "Microns"], L Quantity[70, "Millimeters"], 
   theta \[Degree], phi \[Degree]], 
  "mL/min"], {{L, 70, "wick length"}, 1, 
  100}, {{d, 6.8, "wick diameter"}, 1, 8}, {c, 1/60, 1/
  30}, {{eps, 0.5, "porosity"}, 0.3, 0.9}, {{Rb, 100, "fiber radius"},
   10, 200}, {{theta, 70, "contact angle"}, 0, 
  90}, {{phi, 90, "wick orientation"}, 0, 90}]

Units with corrected manipulate

POSTED BY: Tim Laska

Thanks Tim. That is a much less problematic way of defining 'g'

Hey Tim Thanks for your reply. I altered my code slightly to make it more readable and may have accidentally removed a bracket. It evaluates correctly in my notebook document. I'm confident that's not the issue here. I have tried the ctrl= method of adding units with the same level of success as using the Quantity[] syntax. Sorry, I didn't mention that in my original post, I'd forgotten about that. Bill

Hi William,

Since I am not quite sure about your equation and where you want to put quantities, I threw together this example of calculating capillary rise in inches with a variety of input units using Units Discovery and Manipulate:

capillaryRise[gamma_, theta_, rho_, g_, r_] := 
 2 gamma Cos[theta] / (rho g r)
Manipulate[
 UnitConvert[
  capillaryRise[gamma Quantity[1, (("Dynes")/("Centimeters"))], 
   theta \[Degree], Quantity[1, ("Grams")/("Centimeters")^3], 
   Quantity[9.8, ("Meters")/("Seconds")^2], r Quantity[1, "Microns"]],
   "inch"], {gamma, 1, 80}, {theta, 0, 180}, {r, 1, 1000}]

Units Discovery Example

Does this example help?

POSTED BY: Tim Laska

When I copied your Manipulate expression, Mathematica indicates that the your parentheses are unbalanced (one more right paren than left). You will need to check that first.

Second, you may want to use the Unit Discovery feature by typing ctrl+=. You may want to check out my post https://community.wolfram.com/groups/-/m/t/1560271?ppauth=e8bMDzPu for an example of using Units Discovery and UnitConvert.

POSTED BY: Tim Laska
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard