Units - Maple Help

There were several updates to working with units in Maple 2022.

Visualization and Units

The useunits option

 • The useunits option to the plot and plot3d commands has been overhauled. It now rescales the plot data to conform to the units you specify (in most cases; there is one exception detailed on its help page).
 > height := acceleration/2 * time^2 + initial_velocity * time;
 ${\mathrm{height}}{≔}\frac{{1}}{{2}}{}{\mathrm{acceleration}}{}{{\mathrm{time}}}^{{2}}{+}{\mathrm{initial_velocity}}{}{\mathrm{time}}$ (1)
 > acceleration := -9.81*Unit(m/s^2);
 ${\mathrm{acceleration}}{≔}{-}{9.81}{}⟦\frac{{m}}{{{s}}^{{2}}}⟧$ (2)
 > initial_velocity := 19*Unit(m/s);
 ${\mathrm{initial_velocity}}{≔}{19}{}⟦\frac{{m}}{{s}}⟧$ (3)
 • The default units are seconds on the horizontal axis and meters on the vertical axis.
 > plot(height, time = 0 .. 4*Unit(s));
 • We can override this with the useunits option. Note that the plot data are scaled.
 > plot(height, time = 0 .. 4*Unit(s), useunits=[ms, ft]);
 • If you specify an incompatible unit, Maple issues an error.
 > plot(height, time = 0 .. 4*Unit(s), useunits=[ms, ft/s]);
 • This also works with the plot3d command.
 > unassign('initial_velocity');
 > plot3d(height, time = 0 .. 10*Unit(s), initial_velocity = 0 .. 20*Unit(m/s));
 > plot3d(height, time = 0 .. 10*Unit(s), initial_velocity = 0 .. 20*Unit(m/s), useunits=[ms, ft/s, ft]);

Lists of procedures in the plot and plot3d commands

 • As of Maple 2022, Maple accepts units in calls to the plot and plot3d commands when the object to be plotted is a list of procedures.
 > f_expr := 2.5*sin(t)*Unit(m);
 ${\mathrm{f_expr}}{≔}{2.5}{}{\mathrm{sin}}{}\left({t}\right){}⟦{m}⟧$ (4)
 > f_proc := t -> 2.5*sin(t)*Unit(m);
 ${\mathrm{f_proc}}{≔}{t}{↦}{2.5}{\cdot }{\mathrm{sin}}{}\left({t}\right){\cdot }⟦{m}⟧$ (5)
 > g_expr := 1400*cos(t)*Unit(mm);
 ${\mathrm{g_expr}}{≔}{1400}{}{\mathrm{cos}}{}\left({t}\right){}⟦{\mathrm{mm}}⟧$ (6)
 > g_proc := t -> 1400*cos(t)*Unit(mm);
 ${\mathrm{g_proc}}{≔}{t}{↦}{1400}{\cdot }{\mathrm{cos}}{}\left({t}\right){\cdot }⟦{\mathrm{mm}}⟧$ (7)
 • The following three calls to plot already worked as expected before Maple 2022.
 > plot(f_expr, t=0..2*Pi);
 > plot([f_expr, g_expr], t=0..2*Pi);
 > plot(f_proc, 0..2*Pi, useunits);
 • The following one, however, works only from Maple 2022 onwards.
 > plot([f_proc, g_proc], 0..2*Pi, useunits);

Parametric plots with units

 • The plot and plot3d commands have supported parametric plots for many, many releases. They have supported units since Maple 13. However, before Maple 2022, parametric plots have not supported units. Now they do. Here is a 2-D example with a spiral:
 > radius := 2*sqrt(t/Unit(s)) * Unit(m);
 ${\mathrm{radius}}{≔}{2}{}\sqrt{\frac{{t}}{⟦{s}⟧}}{}⟦{m}⟧$ (8)
 > plot([radius * sin(t/Unit(s)), radius * cos(t/Unit(s)), t = 0 .. 10*Unit(s)]);
 • This 3-D example also uses the useunits option discussed above; it also applies to parametric plots.
 > c1 := [cos(x) - 2*cos(0.4*y*Unit(Hz)), sin(x) - 2*sin(0.4*y*Unit(Hz)), y];
 ${\mathrm{c1}}{≔}\left[{\mathrm{cos}}{}\left({x}\right){-}{2}{}{\mathrm{cos}}{}\left({0.4}{}{y}{}⟦{\mathrm{Hz}}⟧\right){,}{\mathrm{sin}}{}\left({x}\right){-}{2}{}{\mathrm{sin}}{}\left({0.4}{}{y}{}⟦{\mathrm{Hz}}⟧\right){,}{y}\right]$ (9)
 > c2 := [cos(x) + 2*cos(0.4*y*Unit(Hz)), sin(x) + 2*sin(0.4*y*Unit(Hz)), y];
 ${\mathrm{c2}}{≔}\left[{\mathrm{cos}}{}\left({x}\right){+}{2}{}{\mathrm{cos}}{}\left({0.4}{}{y}{}⟦{\mathrm{Hz}}⟧\right){,}{\mathrm{sin}}{}\left({x}\right){+}{2}{}{\mathrm{sin}}{}\left({0.4}{}{y}{}⟦{\mathrm{Hz}}⟧\right){,}{y}\right]$ (10)
 > c3 := [cos(x) + 2*sin(0.4*y*Unit(Hz)), sin(x) - 2*cos(0.4*y*Unit(Hz)), y];
 ${\mathrm{c3}}{≔}\left[{\mathrm{cos}}{}\left({x}\right){+}{2}{}{\mathrm{sin}}{}\left({0.4}{}{y}{}⟦{\mathrm{Hz}}⟧\right){,}{\mathrm{sin}}{}\left({x}\right){-}{2}{}{\mathrm{cos}}{}\left({0.4}{}{y}{}⟦{\mathrm{Hz}}⟧\right){,}{y}\right]$ (11)
 > c4 := [cos(x) - 2*sin(0.4*y*Unit(Hz)), sin(x) + 2*cos(0.4*y*Unit(Hz)), y];
 ${\mathrm{c4}}{≔}\left[{\mathrm{cos}}{}\left({x}\right){-}{2}{}{\mathrm{sin}}{}\left({0.4}{}{y}{}⟦{\mathrm{Hz}}⟧\right){,}{\mathrm{sin}}{}\left({x}\right){+}{2}{}{\mathrm{cos}}{}\left({0.4}{}{y}{}⟦{\mathrm{Hz}}⟧\right){,}{y}\right]$ (12)
 > plot3d({c1, c2, c3, c4}, x = 0 .. 2*Pi, y = 0 .. 10*Unit(s), grid = [25, 15]);
 > plot3d({c1, c2, c3, c4}, x = 0 .. 2*Pi, y = 0 .. 10*Unit(s), grid = [25, 15], useunits=[default, default, Unit(ms)]);

The piecewise Command Now Understands Units

 • The piecewise command is used to construct piecewise-defined expressions. For Maple 2022, we made this command understand units in the conditions that govern switching between the branches of the piecewise command.
 > acceleration := 2*Unit(m/s^2);
 ${\mathrm{acceleration}}{≔}{2}{}⟦\frac{{m}}{{{s}}^{{2}}}⟧$ (13)
 > expr := piecewise(t < 2*Unit(s), 0, t < 3*Unit(s), acceleration/2 * (t - 2*Unit(s))^2, acceleration*(t - 5/2*Unit(s))*Unit(s));
 ${\mathrm{expr}}{≔}\left\{\begin{array}{cc}{0}& {t}{<}{2}{}⟦{s}⟧\\ {\left({t}{-}{2}{}⟦{s}⟧\right)}^{{2}}{}⟦\frac{{m}}{{{s}}^{{2}}}⟧& {t}{<}{3}{}⟦{s}⟧\\ {2}{}\left({t}{-}\frac{{5}}{{2}}{}⟦{s}⟧\right){}⟦\frac{{m}}{{{s}}^{{2}}}⟧{}⟦{s}⟧& {\mathrm{otherwise}}\end{array}\right\$ (14)
 > combine(eval(expr, t = 2200*Unit(ms)), units);
 $\frac{{1}}{{25}}{}⟦{m}⟧$ (15)
 > combine(eval(expr, t = 0.5*Unit(min)), units);
 ${55.00000000}{}⟦{m}⟧$ (16)
 > plot(expr, t = 0 .. 5*Unit(s));

Performance of the Units:-Simple package

 • The Units:-Simple package was introduced in Maple 2017. It provides an easy and powerful way to work with units.
 • Some computations slow down somewhat when using the Units:-Simple package. This is unavoidable, because units-aware operations need to do more work than the default operations. However, for Maple 2022, the units-aware operations in the Units:-Simple package have been sped up considerably for some cases.
 • The computation that follows comes from a slope stability application developed by one of our in-house engineers. To set it up, we load the Units:-Simple package and initialize some variables:
 > with(Units:-Simple):
 > n := 1000:
 > X := Vector(n, i -> i * x__max / n);
 > y__slope := piecewise(x < 33.948*Unit(m), .50076*x, 17 * Unit(m));
 $\mathrm{y__slope}{≔}\left\{\begin{array}{cc}{0.50076}{}{x}& {x}{<}{33.948}{}⟦{m}⟧\\ {17}{}⟦{m}⟧& {\mathrm{otherwise}}\end{array}\right\$ (17)
 > y__fail := evalf(50*Unit(m) - sqrt(2401*Unit(m^2) - x^2));
 $\mathrm{y__fail}{≔}{50.}{}⟦{m}⟧{-}{1.}{}\sqrt{{2401.}{}⟦{{m}}^{{2}}⟧{-}{1.}{}{{x}}^{{2}}}$ (18)
 > rho := 20000*Unit(N/m^3);
 ${\mathrm{\rho }}{≔}{20000}{}⟦\frac{{N}}{{{m}}^{{3}}}⟧$ (19)
 > x__max := 4*sqrt(82)*Unit(m);
 $\mathrm{x__max}{≔}{4}{}\sqrt{{82}}{}⟦{m}⟧$ (20)
 • The time consuming part of the computation now follows.
 > result := Vector(n, i -> x__max / n * eval(y__slope - y__fail, x = X[i]) * rho);
 • This computation was sped up by about a factor 3, comparing to Maple 2021. It also uses about half as much memory in Maple 2022.