SetDirectory["DimensionalAnalysis"];

<<DimensionalAnalysisDemo`
<<Miscellaneous`Units`

x:=12  Meter
y:=3 Hour
x+y

To prevent operations like the one above,  there is a need for a package which would automatically check expressions for their dimensional homogenuity. Such a package must also include functions which allow user to perform dimensional analysis of equations .  Below there is a demonstration on how to perform dimensional analysis (based on Pi theorem) of an unknown function provided all parameters are listed.

Example from hydrodynamics

Consider the drop of pressure p occurring as a result of friction when a  homogenous fluid of constant density ρ flows under steady conditions along a  straight pipe of constant, circular, cross-sectional area d.  The independent relevant quantities and thier dimensions  are listed below:

Here we are not going into details to discuss what  parameters (and why)  are  considered to be important for a particular problem. Interested reader is referred to Massey (1986). Let us first define some conventional notations used in this problem:

Parameters:={p, u, μ, ρ, l, d};

dimension[p]:=dimension[pressure]; 
dimension[u]:=dimension[velocity]; 
dimension[μ] := dimension[viscosity]; 
dimension[ρ]:=dimension[density]; 
dimension[l]:=dimension[length]; 
dimension[d]:=dimension[length];

dimensions:=dimension[#]&/@Parameters;dimensions

The quantity of our primary interest is pressure, so we do not want it to appear in the recurring set:

RestrictedSet:={p, d};

According to Π theorem, we start forming a recurring set  by  finding parameters which involve each of the reference magnitudes from CurrentBasicUnits:

CommonBasicUnits:=MechanicalBasicUnits;

For this problem there are many ways of formulating recurring sets:

AllRecSets:=Evaluate[FindRecurringSet[Parameters]]; AllRecSets

We can, however, indicate that we want, say, l to be in the recurring set. This is done using an options ParInRecSet->{l}

Options[FindRecurringSet]

?ParInRecSet

AllRecSets := 
      Evaluate[FindRecurringSet[Parameters,  ParInRecSet -> {l}]];  
    AllRecSets

Function NondimensionalRules[] returns rules to nondimensionalize all parameters for each recurring set:

AllNonDimRules:=Evaluate[NondimensionalRules[AllRecSets, Parameters]]; 
AllNonDimRules

Nondimensionalization rules are now substituted into the (unknown) function for p which now only depends on 5-3=2 parameters (Partonondim):

Partonondim:=Complement[Parameters, #]&/@AllRecSets; Partonondim

newrules:=AllNonDimRules[[1]];
Eqn1:=(p==psample[Sequence@@Complement[Partonondim[[1]], {p}]]) /. newrules; Eqn1

The next step is usually to find out whether any known named dimensionless parameters are encountered in the expression. The first step is to go from notations to the descriptions of physical quantities using $ToQuantity rules. The default values of these rule are

$ToQuantity

can easily be changed by a user.  Then, a set of rules for changing certain combinations of physical quantities into Named dimensionless paramters ($ToNamedDimensionlessPara) is  applied. Here NamedDimensionlessPara includes only Reynolds number, Re.

arglist := Complement[Partonondim[[1]],  {p}]  /.  newrules; 
    arglist

argrules := Evaluate[RulesToDimensionlessPara[arglist]];  argrules

newarglist := arglist  /.  argrules;  newarglist

eqn1 := (p  /.  newrules) == psample[Sequence@@newarglist];  eqn1

Similarly, for two other recurring sets:

newrules:=AllNonDimRules[[2]]; 
arglist:=Complement[Partonondim[[2]], {p}] /. newrules; 
argrules:=Evaluate[RulesToDimensionlessPara[arglist]]; 
newarglist:=arglist /. argrules; 
Eqn2:=(p /. newrules) ==psample[Sequence@@newarglist]; Eqn2

newrules:=AllNonDimRules[[3]]; 
arglist:=Complement[Partonondim[[3]], {p}] /. newrules; 
argrules:=Evaluate[RulesToDimensionlessPara[arglist]]; 
newarglist:=arglist /. argrules; 
Eqn3:=(p /. newrules)==psample[Sequence@@newarglist]; Eqn3

All three recurring sets and their respective solutions are equally good depending on what relationships are under study. For example, if the effect   of viscosity is to be studied, Eqn. 1 or 3 are rather inconvinient, as μ   appears in both Re and in nondimensional pressure. For this purpose, Eqn 2   where μ only appears in Re would be better.

On cooking and dimensional analysis

This example is taken from the paper "On cooking a roast" by M.S.Klamkin (SIAM Review, 1961, Vol.3(2), 167-169).
The main aim of the Klamkin's note is to establish how the "proper" time of cooking depends on the weight of a roast. 
General assumptions are first that the roasts form a homogeneous isotropic homothetic family; secondly, that the oven is maintained at a fixed roasting temperature; thirdly, that the roasts have the same initial temperature; and that the roasts are considered to be properly cooked when the center temperature reaches a certain fixed temperature. So, parameters defining the problem are:

Parameters := {l,  c,  ρ,  t,  γ};

Here c is heat capacity, γ is thermal conductivity, ρ is density, l is characteristic length (e.g. diameter of the piece of roast),  and t is time to cook the roast till fixed temperature θo.

dimension[c]:=dimension[heatcapacity]; 
dimension[γ]:=dimension[thermalconductivity]; 
dimension[ρ]:=dimension[density]; 
dimension[l]:=dimension[length]; 
dimension[t]:=dimension[time];

dimensions:=dimension[#]&/@Parameters;dimensions

The quantity of our primary interest is time and we want to know how it depends on the size (or weight) of the roast. As the roas is considered to be properly cooked at certain fixed temperature, θ is also excluded from the recurring set.

RestrictedSet:={t};

According to Π theorem, we start forming a recurring set  by  finding parameters which involve each of the reference magnitudes from CurrentBasicUnits:

CommonBasicUnits:=ThermodynamicalBasicUnits; CommonBasicUnits

For this problem there are many ways of formulating recurring sets:

AllRecSets:=Evaluate[FindRecurringSet[Parameters]]; AllRecSets

AllNonDimRules:=Evaluate[NondimensionalRules[AllRecSets, Parameters]]; 
AllNonDimRules

Substitution of these nondimensionalization rules into the (unknown) dependency of time on other roast parameters yields

Partonondim:=Complement[Parameters, #]&/@AllRecSets; Partonondim

newrules:=AllNonDimRules[[1]];
Eqn1:=(t==tsample[Sequence@@Complement[Partonondim[[1]], {t}]]) /. newrules; Eqn1

As all roasts are assumed to have similar heat capacity, thermal conductivity and density, we obtain from the previous that time to cook a roast is simply proportional to the square of some characteristic length of the roast:

t~l^2*ϕsample[]

Here ϕsample[] is a constant  (of dimension T*L^(-2)).   Weight of the roast is proportional to the cube of the length w~l^3, thus resulting in a very important conclusion. The proper time of cooking the proper roast is proportional to the two-thirds power of its weight! This result has been obtained by Murray Klamkin (1961) who argured with the cookbooks suggesting that the time of cooking is simply proportional to its weight.   Excellent example demonstrating dimensional analysis for cooks. SAY ABOUT TURKEY AS WELL!!!