Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_33_1/libs/mpl/doc/tutorial/dimensional-analysis.html @ 12

Last change on this file since 12 was 12, checked in by landauf, 18 years ago

added boost

File size: 6.6 KB
Line 
1<?xml version="1.0" encoding="utf-8" ?>
2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4<head>
5<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6<meta name="generator" content="Docutils 0.3.6: http://docutils.sourceforge.net/" />
7<title>THE BOOST MPL LIBRARY: Dimensional Analysis</title>
8<link rel="stylesheet" href="../style.css" type="text/css" />
9</head>
10<body class="docframe">
11<table class="header"><tr class="header"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./tutorial-metafunctions.html" class="navigation-link">Prev</a>&nbsp;<a href="./representing-dimensions.html" class="navigation-link">Next</a></span><span class="navigation-group-separator">&nbsp;|&nbsp;</span><span class="navigation-group">Back&nbsp;<a href="./higher-order.html" class="navigation-link">Along</a></span><span class="navigation-group-separator">&nbsp;|&nbsp;</span><span class="navigation-group"><a href="./tutorial-metafunctions.html" class="navigation-link">Up</a>&nbsp;<a href="../index.html" class="navigation-link">Home</a></span><span class="navigation-group-separator">&nbsp;|&nbsp;</span><span class="navigation-group"><a href="./tutorial_toc.html" class="navigation-link">Full TOC</a></span></td>
12<td class="header-group page-location"><a href="../index.html" class="navigation-link">Front Page</a> / <a href="./tutorial-metafunctions.html" class="navigation-link">Tutorial: Metafunctions and Higher-Order Metaprogramming</a> / <a href="./dimensional-analysis.html" class="navigation-link">Dimensional Analysis</a></td>
13</tr></table><div class="header-separator"></div>
14<div class="section" id="dimensional-analysis">
15<h1><a class="toc-backref" href="./tutorial-metafunctions.html#id41" name="dimensional-analysis">Dimensional Analysis</a></h1>
16<p>The first rule of doing physical calculations
17on paper is that the numbers being manipulated don't stand alone:
18most quantities have attached <em>dimensions</em>, to be ignored at our
19peril.  As computations become more complex, keeping track of
20dimensions is what keeps us from inadvertently assigning a mass to
21what should be a length or adding acceleration to velocity — it
22establishes a type system for numbers.</p>
23<p>Manual checking of types is tedious, and as a result, it's also
24error-prone.  When human beings become bored, their attention
25wanders and they tend to make mistakes.  Doesn't type checking seem
26like the sort of job a computer might be good at, though?  If we
27could establish a framework of C++ types for dimensions and
28quantities, we might be able to catch errors in formulae before
29they cause serious problems in the real world.</p>
30<p>Preventing quantities with different dimensions from interoperating
31isn't hard; we could simply represent dimensions as classes that
32only work with dimensions of the same type.  What makes this
33problem interesting is that different dimensions <em>can</em> be combined,
34via multiplication or division, to produce arbitrarily complex new
35dimensions.  For example, take Newton's law, which relates force to
36mass and acceleration:</p>
37<blockquote>
38<em>F</em> = <em>ma</em></blockquote>
39<p>Since mass and acceleration have different dimensions, the
40dimensions of force must somehow capture their combination.  In
41fact, the dimensions of acceleration are already just such a
42composite, a change in velocity over time:</p>
43<blockquote>
44<em>dv</em>/<em>dt</em></blockquote>
45<p>Since velocity is just change in distance (<em>l</em>) over time (<em>t</em>),
46the fundamental dimensions of acceleration are:</p>
47<blockquote>
48(<em>l</em>/<em>t</em>)/<em>t</em>  =  <em>l</em>/<em>t</em><sup>2</sup></blockquote>
49<p>And indeed, acceleration is commonly measured in &quot;meters per second
50squared.&quot;  It follows that the dimensions of force must be:</p>
51<blockquote>
52<em>ml</em>/<em>t</em><sup>2</sup></blockquote>
53<!-- @litre_translator.line_offset -= 7 -->
54<p>and force is commonly measured in kg(m/s<sup>2</sup>), or
55&quot;kilogram-meters per second squared.&quot;  When multiplying quantities
56of mass and acceleration, we multiply their dimensions as well and
57carry the result along, which helps us to ensure that the result is
58meaningful.  The formal name for this bookkeeping is <strong>dimensional
59analysis</strong>, and our next task will be to implement its rules in the C++
60type system.  John Barton and Lee Nackman were the first to show
61how to do this in their seminal book, <em>Scientific and Engineering
62C++</em> <a class="citation-reference" href="#bn94" id="id5" name="id5">[BN94]</a>.  We will recast their approach here in
63metaprogramming terms.</p>
64<table class="citation" frame="void" id="bn94" rules="none">
65<colgroup><col class="label" /><col /></colgroup>
66<tbody valign="top">
67<tr><td class="label"><a class="fn-backref" href="#id5" name="bn94">[BN94]</a></td><td>John J. Barton and Lee R. Nackman. <em>Scientific and
68Engineering C++: an Introduction with Advanced Techniques and
69Examples.</em> Reading, MA: Addison Wesley. ISBN
700-201-53393-6. 1994.</td></tr>
71</tbody>
72</table>
73<ul class="toc simple" id="outline">
74<li><a class="reference" href="./representing-dimensions.html" id="id42" name="id42">Representing Dimensions</a></li>
75<li><a class="reference" href="./representing-quantities.html" id="id43" name="id43">Representing Quantities</a></li>
76<li><a class="reference" href="./implementing-addition-and.html" id="id44" name="id44">Implementing Addition and Subtraction</a></li>
77<li><a class="reference" href="./implementing.html" id="id45" name="id45">Implementing Multiplication</a></li>
78<li><a class="reference" href="./implementing-division.html" id="id46" name="id46">Implementing Division</a></li>
79</ul>
80</div>
81
82<div class="footer-separator"></div>
83<table class="footer"><tr class="footer"><td class="header-group navigation-bar"><span class="navigation-group"><a href="./tutorial-metafunctions.html" class="navigation-link">Prev</a>&nbsp;<a href="./representing-dimensions.html" class="navigation-link">Next</a></span><span class="navigation-group-separator">&nbsp;|&nbsp;</span><span class="navigation-group">Back&nbsp;<a href="./higher-order.html" class="navigation-link">Along</a></span><span class="navigation-group-separator">&nbsp;|&nbsp;</span><span class="navigation-group"><a href="./tutorial-metafunctions.html" class="navigation-link">Up</a>&nbsp;<a href="../index.html" class="navigation-link">Home</a></span><span class="navigation-group-separator">&nbsp;|&nbsp;</span><span class="navigation-group"><a href="./tutorial_toc.html" class="navigation-link">Full TOC</a></span></td>
84</tr></table></body>
85</html>
Note: See TracBrowser for help on using the repository browser.