Units Updates in Maple 2022
There were several updates to working with units in Maple 2022.
Visualization and Units
The piecewise Command Now Understands Units
Performance of the Units:-Simple package
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;
height≔12⁢acceleration⁢time2+initial_velocity⁢time
acceleration := -9.81*Unit(m/s^2);
acceleration≔−9.81⁢ms2
initial_velocity := 19*Unit(m/s);
initial_velocity≔19⁢ms
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]);
Error, (in plot) incompatible units found: expected units compatible with Units:-Unit(ft/s), but found -4.905000000*Units:-Unit(m/s^2)*time^2+19*Units:-Unit(m/s)*time
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);
f_expr≔2.5⁢sin⁡t⁢m
f_proc := t -> 2.5*sin(t)*Unit(m);
f_proc≔t↦2.5⋅sin⁡t⋅m
g_expr := 1400*cos(t)*Unit(mm);
g_expr≔1400⁢cos⁡t⁢mm
g_proc := t -> 1400*cos(t)*Unit(mm);
g_proc≔t↦1400⋅cos⁡t⋅mm
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);
radius≔2⁢ts⁢m
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];
c1≔cos⁡x−2⁢cos⁡0.4⁢y⁢Hz,sin⁡x−2⁢sin⁡0.4⁢y⁢Hz,y
c2 := [cos(x) + 2*cos(0.4*y*Unit(Hz)), sin(x) + 2*sin(0.4*y*Unit(Hz)), y];
c2≔cos⁡x+2⁢cos⁡0.4⁢y⁢Hz,sin⁡x+2⁢sin⁡0.4⁢y⁢Hz,y
c3 := [cos(x) + 2*sin(0.4*y*Unit(Hz)), sin(x) - 2*cos(0.4*y*Unit(Hz)), y];
c3≔cos⁡x+2⁢sin⁡0.4⁢y⁢Hz,sin⁡x−2⁢cos⁡0.4⁢y⁢Hz,y
c4 := [cos(x) - 2*sin(0.4*y*Unit(Hz)), sin(x) + 2*cos(0.4*y*Unit(Hz)), y];
c4≔cos⁡x−2⁢sin⁡0.4⁢y⁢Hz,sin⁡x+2⁢cos⁡0.4⁢y⁢Hz,y
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 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);
acceleration≔2⁢ms2
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));
expr≔0t<2⁢st−2⁢s2⁢ms2t<3⁢s2⁢t−52⁢s⁢ms2⁢sotherwise
combine(eval(expr, t = 2200*Unit(ms)), units);
125⁢m
combine(eval(expr, t = 0.5*Unit(min)), units);
55.00000000⁢m
plot(expr, t = 0 .. 5*Unit(s));
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));
y__slope≔0.50076⁢xx<33.948⁢m17⁢motherwise
y__fail := evalf(50*Unit(m) - sqrt(2401*Unit(m^2) - x^2));
y__fail≔50.⁢m−1.⁢2401.⁢m2−1.⁢x2
rho := 20000*Unit(N/m^3);
ρ≔20000⁢Nm3
x__max := 4*sqrt(82)*Unit(m);
x__max≔4⁢82⁢m
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.
Download Help Document