{"id":5787,"date":"2024-06-26T09:28:53","date_gmt":"2024-06-26T07:28:53","guid":{"rendered":"https:\/\/oopm.org\/?page_id=5787"},"modified":"2024-12-04T10:06:13","modified_gmt":"2024-12-04T09:06:13","slug":"5-4x-values","status":"publish","type":"page","link":"https:\/\/oopm.org\/?page_id=5787","title":{"rendered":"5.6 Dimensions and units"},"content":{"rendered":"<div class=\"pdfprnt-buttons pdfprnt-buttons-page pdfprnt-top-right\"><a href=\"https:\/\/oopm.org\/index.php?rest_route=wpv2pages5787&print=pdf\" class=\"pdfprnt-button pdfprnt-button-pdf\" target=\"_blank\"><img decoding=\"async\" src=\"https:\/\/oopm.org\/wp-content\/plugins\/pdf-print\/images\/pdf.png\" alt=\"image_pdf\" title=\"View PDF\" \/><\/a><a href=\"https:\/\/oopm.org\/index.php?rest_route=wpv2pages5787&print=print\" class=\"pdfprnt-button pdfprnt-button-print\" target=\"_blank\"><img decoding=\"async\" src=\"https:\/\/oopm.org\/wp-content\/plugins\/pdf-print\/images\/print.png\" alt=\"image_print\" title=\"Print Content\" \/><\/a><\/div>\n<p class=\"wp-block-paragraph\">Properties of physical entities are as mentioned often represented by value objects. Such properties are often called <em>quantities<\/em>. A quantity may represent properties like length, mass, speed and velocity of a physical entity like a vehicle. A quantity can be denoted by measurement that consist of a number (called the <em>magnitude<\/em> of the measurement) and a <em>unit<\/em>. As an example 12 centimers is a measurement of a quantity length where the magnitude is 12 and the unit is centimeters.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So far we have used primitive values like float to represent the <em>magnitude<\/em> (value) of a quantity. A quantity, however, also has an associated unit. It is thus important to be able to represent the unit being associated with a given quantity.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Consider a physical entity like a car. It has properties (quantities) length and weight. The length may be measured in centimeter, and its weight may be measured in kilograms. If we just use a float we are not able to distinguish between values of these two properties:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>class<\/strong> Car:\n   l: <strong>var<\/strong> float\n   w: <strong>var<\/strong> float <\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">There is nothing that prevents us from assigning <code>l<\/code> to <code>w<\/code> (<code>w := l<\/code>) or compare <code>l<\/code> and <code>w<\/code> (<code>l = w<\/code>) since the compiler only knows that <code>l<\/code> and <code>w<\/code> are two floats.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To handle this, we may specify the unit of <code>l<\/code> and <code>w<\/code> as follows:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>class<\/strong> Car:\n   l: <strong>var<\/strong> Length.Centimeter\n   w: <strong>var<\/strong> Mass.Kilogram<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Here <code>Length<\/code> is a singular object representing the dimension length as defined by the <a href=\"https:\/\/en.wikipedia.org\/wiki\/International_System_of_Units\">International System of Units (SI)<\/a>. <code>Length<\/code> defines local types (classes) representing units like <code>Millimeter<\/code>, <code>Centimeter<\/code>, <code>Meter<\/code>, etc.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>Mass<\/code> is a singular object that in a similar way represents the dimension mass as defined by SI, and it has types like <code>Kilogram<\/code>, <code>Gram<\/code>, etc.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When <code>l<\/code> and <code>w<\/code> are declared as above, the compiler prevents assignments like <code>w := l<\/code> since <code>w<\/code> and <code>l<\/code> have different types. And a comparison like <code>l = w<\/code> is also prevented.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The types <code>Centimeter<\/code> and <code>Kilogram<\/code> include a <code>float<\/code> representing the numerical value of the magnitude of the quantity as well as the unit of the quantity.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Data-items representing quantities may be assigned a numerical value, but a unit has to be supplied:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>l := 3.1 m\nw := 12 kg<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The variable <code>l<\/code> as assigned 3.1 meter and <code>w<\/code> is assigned 12 kilogram.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Addition and subtraction of quantities gives a new quantity of the same dimension. Multiplication, division and exponentiation give a derived dimension. Consider the following example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>l1,l2,l3: <strong>var<\/strong> Length.Meter\na: <strong>var<\/strong> Area.SquareMeter\nl1 := 12 m\nl2 := 3 m\nl3 := l1 + l2 -- gives l3 = 15 m\na := l1 * l2 -- gives a = 36 m2 (squaremeter)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">It is beyond the scope of this book to explain SI in details, but if you have to work with units we recommend that you study the SI. Here we just summarise some of the overall characteristics of SI:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">According to the SI,\u00a0there are seven base dimensions:\u00a0<em>time,<\/em>\u00a0<em>length<\/em>,\u00a0<em>mass<\/em>,\u00a0<em>electric current<\/em>, <em>thermodynamic temperature<\/em>,\u00a0<em>amount of substance<\/em>,\u00a0and <em>luminous intensity<\/em>. There are seven base units, one per dimension, and each base unit has an associated symbol. The units are a.o. the\u00a0<em>second<\/em>\u00a0(the unit of\u00a0<em>time<\/em>\u00a0with the symbol\u00a0<em>s<\/em>),\u00a0<em>meter<\/em>\u00a0(<em>length<\/em>,\u00a0<em>m<\/em>), and\u00a0<em>kilogram<\/em>\u00a0(<em>mass<\/em>,\u00a0<em>kg<\/em>).\u00a0 In addition to the base units each dimension may have a number of other units. Meter is the base unit of length, but other units are centimeter and millimeter.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In addition, there is an unlimited number of additional units, called&nbsp;<em>derived units<\/em>, like&nbsp;<em>area<\/em>,&nbsp;<em>velocity<\/em>, and&nbsp;<em>force<\/em>. A derived unit can always be represented as products and\/or powers of the base units. The unit of area is&nbsp;<em>square meter<\/em>&nbsp;defined as&nbsp;<em>length&nbsp;<\/em>\u22c5&nbsp;<em>length<\/em>; the unit of velocity is <em>length&nbsp;<\/em>\u22c5&nbsp;<em>time<sup>-1<\/sup><\/em>; etc.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The qBeta library includes objects representing several dimensions and associated units as defined in SI.<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-custom-color-3-color\"> <\/mark>These objects are modules as described in chapter <script>mkRef(\"Modules\")<\/script>. The table below shows some of the dimensions and units supported by qBeta.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><td><strong><em>Dimension<\/em><\/strong><\/td><td><strong><em>Unit<\/em><\/strong><\/td><td><strong><em>Module name <\/em><\/strong><\/td><\/tr><tr><td>time<\/td><td>second<\/td><td><code>Time<\/code><\/td><\/tr><tr><td>length<\/td><td>meter<\/td><td><code>Length<\/code><\/td><\/tr><tr><td>mass<\/td><td>kilogram<\/td><td><code>Mass<\/code><\/td><\/tr><tr><td>electric current<\/td><td>ampere<\/td><td><code>ElectricCurrent<\/code><\/td><\/tr><tr><td>thermodynamic temperature<\/td><td>kelvin<\/td><td><code>ThermodynamicTemperature<\/code><\/td><\/tr><tr><td>amount of substance<\/td><td>mole<\/td><td><code>AmountOfSubstance<\/code><\/td><\/tr><tr><td>luminous intensity<\/td><td>candela<\/td><td><code>LuminousIntensity<\/code><\/td><\/tr><tr><td>area<\/td><td>square meter<\/td><td><code>Area<\/code><\/td><\/tr><tr><td>volume<\/td><td>cubic meter<\/td><td><code>Volume<\/code><\/td><\/tr><tr><td>velocity<\/td><td>meter per second<\/td><td><code>Velocity<\/code><\/td><\/tr><tr><td>acceleration<\/td><td>meter per second squared<\/td><td><code>Acceleration<\/code><\/td><\/tr><tr><td>force <\/td><td>newton<\/td><td><code>Force<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n<div style=\"display:flex; gap:10px;justify-content:center\" class=\"wps-pgfw-pdf-generate-icon__wrapper-frontend\">\n\t\t<a  href=\"https:\/\/oopm.org?action=genpdf&amp;id=5787\" class=\"pgfw-single-pdf-download-button\" ><img src=\"https:\/\/oopm.org\/wp-content\/plugins\/pdf-generator-for-wp\/admin\/src\/images\/PDF_Tray.svg\" title=\"Generate PDF\" style=\"width:auto; height:45px;\"><\/a>\n\t\t<\/div>","protected":false},"excerpt":{"rendered":"<p>Properties of physical entities are as mentioned often represented by value objects. Such properties are often called quantities. A quantity may represent properties like length, mass, speed and velocity of a physical entity like a vehicle. A quantity can be denoted by measurement that consist of a number (called the magnitude of the measurement) and [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":2270,"menu_order":6,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-5787","page","type-page","status-publish","hentry"],"mb":[],"mfb_rest_fields":["title","gutenberg_elementor_mode"],"_links":{"self":[{"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages\/5787","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/oopm.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5787"}],"version-history":[{"count":27,"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages\/5787\/revisions"}],"predecessor-version":[{"id":10061,"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages\/5787\/revisions\/10061"}],"up":[{"embeddable":true,"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages\/2270"}],"wp:attachment":[{"href":"https:\/\/oopm.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5787"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}