BACK | 2 | NEXT | Up next: Learn about some of the quirks of
Dimensional, helpful for troubleshooting.
My fictitious vehicle's fuel consumption rate is dependent on several factors:
From these terms, we can conclude that the fuel consumption (\(Q\)) is directly proportional to acceleration (\(a\)) and speed (\(v\)), and inversely proportional to weight (\(f\)), plus a constant term (\(C\)). We want to know two things:
Let's set up our equation and substitute in our variables:
$$\text{Fuel consumption} = x \times \left[ \frac{\text{Acceleration} \times \text{Speed}}{\text{Weight}} + \text{C} \right]$$
$$Q = x \times \left[ \frac{a \times v}{f} + C \right]$$
From our dimensional analysis or physics class that we paid attention in, we know that we can only add terms of like dimensions, so that means that:
$$\dim\left(C\right) = \dim\left(\frac{a \times v}{f}\right)$$
We can also isolate \(x\) to determine its dimensionality as well:
$$\dim\left(x\right) = \dim\left(\frac{\frac{a \times v}{f} + C}{Q}\right) = \dim\left(\frac{\text{C}}{\text{Q}}\right)$$
Use Dimensional to define each one of the known dimensions and calculate the unknown dimensions for \(C\) and \(x\).
Follow these steps to create a new project workspace and install the dimensional dependency to run this example.
# Create and open project folder
mkdir Dimensional_Analysis_demo
cd Dimensional_Analysis_demo
# Initialize project and install dependencies
npm init -y
npm i dimensional@1.3.1
# Create and open source file
touch "Dimensional Analysis.mjs"
open "Dimensional Analysis.mjs"
Copy and paste this source code into Dimensional Analysis.mjs.
import { dimensions } from 'dimensional';
// Define our dimensions
const a = dimensions.acceleration; // Acceleration
const v = dimensions.velocity; // Speed
const f = dimensions.force; // Weight
const Q = dimensions.volume.over(dimensions.Time); // Fuel consumption, e.g. gal/min - not a default dimension
// Determine dimensions on C (idling constant term)
const C = a.times(v).over(f);
console.log(C.toString());
// Determine dimensions on x (proportionality constant)
const x = C.over(Q);
console.log(x.toString());
In Dimensional_Analysis_demo/, execute Dimensional Analysis.mjs with NodeJS to generate an output.
node "Dimensional Analysis.mjs"
You should expect to see an output similar to the one below.
\frac{{\textbf{L}}}{{\textbf{T}} \cdot {\textbf{M}}}
\frac{1}{{\textbf{L}}^{2} \cdot {\textbf{M}}}