Dimensional Analysis

from Essential Mathematica for Students of Science
© James J. Kelly, 1998
Last revised: January, 2006

Introduction

In science and engineering one is constantly manipulating functions and relationships that involve quantities with physical dimensions and whose numerical values depend upon the system of units employed.  In fact, your previous instructors probably insisted that the value obtained for any dimensioned quantity must be accompanied by its units and you were probably annoyed by losing credit on homework and tests for omitting units from numerically correct results.  The reason for insisting upon carrying the units is that relationships that are not dimensionally consistent cannot be meaningful and numerical calculations that are not expressed in a consistent set of units will not be correct either even if dimensionally consistent.  However, those of you who have computed physical quantities using a computer quickly discovered that compiled languages handle only numerical values and do not readily accommodate units — all quantities must be expressed numerically and it is the programmer's responsibility to ensure consistency of both dimensions and units.  Interpreted languages, like Mathematica, permit units to be attached to values in the form of symbolic factors and conversions to be expressed by replacement rules.  Thus, it is possible to satisfy the professor's insistence upon units and still enjoy the advantages of electronic computation.  However, because many operations, like plotting, remain limited to purely numerical quantities, symbolic units can still be more of a nuisance than a help.

In this notebook we explore some of the techniques for manipulating dimensioned quantities.

Initialization

ClearAll["Global`*"];
Off[General::spell, General::spell1]

Needs["Miscellaneous`PhysicalConstants`"];
Needs["Miscellaneous`Units`"]

Verifying dimensional consistency

Suppose you derive or are given an equation involving dimensioned quantities and wish to verify that the dimensions are consistent.  If you were doing this by hand, you would express all symbols in terms of their fundamental dimensions:  Mass, Length, Time, Temperature, etc.  Then you would verify that each term has the same dimensions, meaning that the powers match, while ignoring numerical coefficients.

For example, the gravitational acceleration g at radius r outside a sphere of mass M is given by g = ((G M)/(r^2)) where G is the gravitational constant.  We verify the dimensional consistency of this formula below.

g == ((G M)/(r^2)) //. {g -> Acceleration, 
        Acceleration -> (Length/(Time^2)), M -> Mass, 
        r -> Length, G -> (Force/(((Mass^2)/(Length^2)))), 
        Force -> Mass Acceleration}

Of course, this example is so simple that formulating these rules might seem to be more trouble than it's worth.  However, if we collect these and related rules together they can be applied to more complicated problems later.  Additional rules can be included as the need arises.

dimrules = {Velocity -> (Length/Time), 
          Acceleration -> (Velocity/Time), 
          Force -> Mass Acceleration, Energy -> Force Length, 
          G -> (Force/(((Mass^2)/(Length^2)))), 
          c -> Velocity,  ℏ -> Energy Time};

g == ((G M)/(r^2)) /. {g -> Acceleration, M -> Mass, 
          r -> Length} //. dimrules

Alternatively, suppose you know that some quantity must arise as a simple product of powers of fundamental constants.  For example, the mass scale for which quantum mechanics affects gravity must involve the fundamental parameter of quantum mechanics, ℏ, the fundamental parameter of gravity, G, and the fundamental parameter of relativity, c.  The mass constructed from these fundamental constants is known as the Planck mass.  Similarly, these constants can also be used to define a Planck length and a Planck time because three constants that involve three physical dimensions can be combined to form three independent scales, one for each of the dimensions involved.

To determine the Planck scales, we combine these fundamental constants as a product with undetermined exponents

product = (ℏ^α) (G^β) (c^γ) //. 
          dimrules // PowerExpand

and then develop systems of equations

eqs = 
      product /. {(Mass^a)_ (Length^b)_ 
              (Time^c)_ -> {{a == 1, b == 0, 
                c == 0}, {a == 0, b == 1, 
                c == 0}, {a == 0, b == 0, 
                c == 1}} }

whose solutions give the combinations of exponents that yield quantities which depend upon a single physical dimension

PlanckScalesSymbolic = {Planck[Mass], Planck[Length], 
          Planck[Time]} = (ℏ^α) (G^β) (c^γ) /. 
                Solve[#, {α, β, γ}] &  /@  eqs  // 
          Flatten

You should check for yourself that these expressions do indeed yield unique mass, length, and time scales.

Evaluate the Planck temperature scale by including the Temperature dimension and the Boltzmann constant, (Subscript[k, B]) with dimensions of Energy/Temperature, in the foregoing analysis.

The oscillation period of a simple pendulum must depend upon its length ℓ, mass m, and the gravitational acceleration, g.  Use dimensional analysis to determine how the period must scale with these parameters.

The vibrational frequency for a stretched string can depend upon its tension T, length ℓ, and mass per unit length, μ.  Use dimensional analysis to determine how the frequency must scale with these parameters.  Is this consistent with what you know about guitar strings?

Units

Standards

Even though we have already used the Mathematica packages Miscellaneous`PhysicalConstants` and Miscellaneous`Units` in the notebook getting started, it is worth reviewing the meaning of dimensions and units.  A quantity with dimensions, such as length or mass, can be assigned a numerical value only by comparison with an established standard of measurement.  For example, the primary standard of length used to be the separation between two lines inscribed upon a particular platinum-iridium bar maintained under carefully controlled conditions of temperature and humidity by the International Bureau of Weights and Measures in Sèvres, France.  In principle, secondary standards would be manufactured by comparison with the primary standard and then length measurements would be made in various laboratories by reference to these secondary standards.  Although the standard of length was redefined in 1983 and is now based upon the speed of light and a standard of time derived from an atomic clock, the fundamental idea is that dimensioned quantities must always be measured relative to some physical standard which serves as the unit of measure.  Thus, the fact that my diminutive stature is 1.42 times the standard unit of length is expressed as a height of 1.42 meters.

The definitions of measurement units are quite arbitrary, reflecting a long history of human quirks, and would be practically useless without international standardization.  Modern scientific measurements are based upon the Système International d'Unités (International System of Units), known as SI units, maintained by an international committee.  The physical constants stored in the Mathematica package Miscellaneous`PhysicalConstants` are expressed in SI units.  The following command produces a list of the available constants.

?Miscellaneous`PhysicalConstants`*

For example, the gravitational constant is

GravitationalConstant

If we now evaluate the Planck mass, length, and time using these constants

PlanckScalesNumeric = PlanckScalesSymbolic /. {ℏ -> 
                PlanckConstantReduced, G -> GravitationalConstant, 
              c -> SpeedOfLight} // PowerExpand // Simplify

we obtain correct but unsightly expressions in which the derived units of force and energy are not simplified.  Unfortunately, the Mathematica packages do not provide any method for simplifying expressions of this type, but we can easily write replacement rules which accomplish this task.

PlanckScalesNumeric =  
      PlanckScalesNumeric //. {Joule -> Newton Meter, 
            Newton -> Kilogram Meter (Second^(-2))} // 
        PowerExpand

Alternatively, if one agrees to express all physical quantities in SI units and knows that all relevant expressions are dimensionally consistent, then it is not necessary to carry the units in numerical calculations.  Each constant is represented in the form of a product that contains a numerical coefficient and a symbol representing the appropriate unit or combination of units.  For example, the full form of the gravitational constant is

FullForm[ GravitationalConstant ]

The numerical value of a constant is then simply its first part

GravitationalConstant[[1]]

Thus, we can obtain the Planck scales in SI units

PlanckScalesSymbolic /. {ℏ -> 
          PlanckConstantReduced[[1]], 
        G -> 
          GravitationalConstant[[1]], 
        c -> 
          SpeedOfLight[[1]]}

without manipulating the units.  Actually, the PhysicalConstants package provides a value for the Planck mass which agrees with our result.

PlanckMass

This value for the Planck mass may seem to be quite small, but it is actually quite large compared with the masses of known elementary particles, such as the electron.

PlanckMass/ElectronMass

Compute the gravitational acceleration at the earth's surface using values for the mass and radius of the earth from PhysicalConstants.

Conversions

Often one is presented with quantities expressed in British, engineering, or other units.  The command SI[quantity] converts to SI units.

SI[Horsepower]

SI[Slug]

SI[BTU]

?Convert

More generally, Convert[quantity,units] converts a quantity to a new set of dimensionally consistent units.

Convert[0.5 Acre,  (Meter^2)]

Convert[Parsec, LightYear]

Convert simply multiplies by the appropriate scale factor, but for temperature there can be an offset in addition to a scale factor.  Therefore, for temperature it is better to use ConvertTemperature.

?ConvertTem*

ConvertTemperature[32. ,  Fahrenheit, Kelvin]

Difficulties with dimensioned quantities

If one attempts to write a function for the gravitational field of a uniform sphere using arguments which may have units (such as radius in meters and mass in kilograms), one is likely to encounter some difficulties that are instructive in themselves.  The first attempt made by many students looks something like this.

Clear[g, r, R, M, G];
g[r_  /; r > R]  :=   ((G M)/(r^2));
g[r_  /;  r ≤ R] := ((G M)/(R^3)) r

However, there are two reasons that this approach does not work well.  First, because the condition applied to the lhs depends upon both r and R, the condition cannot be evaluated unless R has a preset value .

Table[g[r], {r, 0, 2, 0.5}]

R = 1;
Table[g[r], {r, 0, 2, 0.5}]

Second, if the variables in the problem have dimensions the condition may not be evaluated correctly.  We will return to this difficulty again later, but for now consider the following attempt to produce symbolic values in terms of R.

Clear[R];
Table[g[r], {r, 0, 2 R, 0.5 R}]

The function remains unevaluated because the condition cannot be evaluated.

0.5 R ≤ R

Why not — isn't it obvious that 0.5 R is less than R?  Actually, it is not obvious to Mathematica because, without your intuition about the meaning of the symbols, it does not automatically assume that R is positive.

A better version of this function includes all variables as arguments.  We consider the radius and mass of the object to be variables because they depend upon the particular object under consideration, but we consider G to be a parameter because it is a universal constant of nature.  Therefore, we include R and M as arguments but omit G.  Because our conditions now depend upon two arguments, we must place the conditions on the rhs of the function definitions.  We also include a dimensionless form in which g is expressed as a fraction of the surface gravity G M /(R^2) and r is measured relative to the surface radius R.

Clear[g, r, R, M, G];
g[r_, R_, M_] :=  ((G M)/(r^2)) /; r > R ;
g[r_, R_, M_] := ((G M)/(R^3)) r  /;  
          r ≤ R ;
g[r_]  :=  g[r, 1, 1] /. G -> 1

Plot[g[r], {r, 0, 3}];

However, this does not solve our difficulties for dimensioned quantities.  To be more specific, let us use parameters for the earth.  The obvious way to compute the surface gravity would be to assign values to the variables that include the units.

earthParameters = {G -> GravitationalConstant, 
          R -> EarthRadius, M -> EarthMass};

g[R, R, M] /. earthParameters

Unfortunately, the obvious approach fails!  It is instructive to use Trace to investigate the problem.

g[R, R, M] /. earthParameters  // Trace

Although the output it fairly cryptic, one soon discovers that our difficulties are related to the failure to properly evaluate the following condition.

EarthRadius  ≤ EarthRadius

How can this fail?  We can understand that the failure to evaluate 0.5 R ≤ R is to due the program's reluctance to make assumptions about positivity, and we can even forgive the failure to evaluate

0.5 Meter  ≤  Meter

properly even though Mathematica really should know that standard units can be treated as positive quantities, but the failure to evaluate

Clear[a];
a  ≤ a

as True strikes me as a shortcoming.  Evidently, the LessEqual function requires numeric input and does not recognize the fact "a symbol is identical to itself" as an instance of equality between expressions.

Provided that we always express physical parameters in a consistent system of units and consider only dimensionally consistent expression, we can employ numerical values without units.  Thus, we can obtain the SI values for earth parameters by using Part specifications as follows.

earthParameters = {G -> 
            GravitationalConstant[[1]], 
          R -> EarthRadius[[1]], 
          M -> 
            EarthMass[[1]]};

g[R, R, M] //. earthParameters

This value is expressed with respect to the SI unit of acceleration, namely m/(s^2).  Although we consider the dimensionless version to be more informative, we can now plot the gravitational acceleration for this model of the earth using SI units.

\(\(Plot[
        g[r, R, M] //. earthParameters, \ {r, 0, \ 
          3\ EarthRadius[[1]]}, 
        AxesLabel -> {"r   [m]", \*""g  [m/(s^2)]""}];\)\)

In general, it is good practice to identify the scales relevant to any dimensioned quantity and to express related quantities relative to the appropriate scale parameters so that functions can be expressed in numerical form without symbolic units or scales.  Many Mathematica functions, or mathematical functions, require numerical input.  For example, Plot requires its functions to evaluate to pure numbers.  Thus, to plot g(r) we have to extract the dimensions and scales anyway, whether or not those dimensions would pose problems for the formulation of conditions.

Nondimensionalization

Plotting commands deal with pure numbers, but the functions encountered as solutions to problems in science and engineering usually involve quantities with dimensions and units and often have several parameters describing the properties of some system.  Such functions must be nondimensionalized and must evaluate to pure numbers for plotting purposes.  Sometimes this can be done simply by replacing appropriate parameters by unity, effectively rescaling the variables in terms of appropriate dimensional parameters, or by giving explicit values in a consistent system of units.  The axis labels should then specify the units.  Other times we need to re-express the function in terms of appropriate dimensionless combinations of variables and parameters.  It is then appropriate to use axis labels to express the relevant combinations of variables.

For example, the Planck black-body formula

planck[ω, 
        T]  = (((Subscript[k, B]) T (ω^(3 )))/((π^2) (c^2) ((E^(((ℏ ω )/((Subscript[k, B]) T)))) - 1) ))

clearly exhibits a scaling relationship between its temperature and energy variables.  Hence, we can simplify the expression by making the replacement

planck[y]  =  
      planck[ω, T]  /. ω -> (Subscript[k, B]) T y/ℏ  // 
        Simplify

Now we find that the function can be described as a dimensionless function of y times a temperature-dependent normalization factor.  Therefore, to plot this function we need to divide out the normalization factor.  We then obtain a form suitable for plotting and use the labels to report the relevant dimensionless variables.

norm = (((((Subscript[k, B]) T))^4)/((π^2) (ℏ^3) (c^2)));
\(\(Plot[Evaluate[planck[y]/norm], {y, 0, 10}, 
        GridLines -> Automatic, Frame -> True, 
        FrameLabel -> {\*""ℏ ω / (Subscript[k, B])T"", \ \*""I / (((Subscript[k, B])T)^4/(π^2)(ℏ^3)(c^2))""}, 
        PlotLabel -> "Planck Distribution"];\)\)

g=((G M)/(R^2))

g = ((G M)/(r^2)) for r ≥ R

g(r)  = ((G  M(r))/(r^2)) for r ≤ R

I[θ]  =  
      (Subscript[I, 0]) f[n, d, λ, θ] g[
          a, λ, θ]

\(TraditionalForm\`f[n, d, λ, θ] = 
      Sin[n\ π\ \(d\/λ\) Sin[θ]]\^2\/Sin[π\ \(d\/λ\) Sin[θ]]\^2\)

\(TraditionalForm\`g[a, λ, θ] = 
      Sin[π\ \(a\/λ\) Sin[θ]]\^2\/\((π\ \(a\/λ\) Sin[θ])\)\^2\)

m  =  (d/λ) 
        Sin[θ]