Units - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


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

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;

height12accelerationtime2+initial_velocitytime

(1)

acceleration := -9.81*Unit(m/s^2);

acceleration9.81ms2

(2)

initial_velocity := 19*Unit(m/s);

initial_velocity19ms

(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]);

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_expr2.5sintm

(4)

f_proc := t -> 2.5*sin(t)*Unit(m);

f_proct2.5sintm

(5)

g_expr := 1400*cos(t)*Unit(mm);

g_expr1400costmm

(6)

g_proc := t -> 1400*cos(t)*Unit(mm);

g_proct1400costmm

(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);

radius2tsm

(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];

c1cosx2cos0.4yHz,sinx2sin0.4yHz,y

(9)

c2 := [cos(x) + 2*cos(0.4*y*Unit(Hz)), sin(x) + 2*sin(0.4*y*Unit(Hz)), y];

c2cosx+2cos0.4yHz,sinx+2sin0.4yHz,y

(10)

c3 := [cos(x) + 2*sin(0.4*y*Unit(Hz)), sin(x) - 2*cos(0.4*y*Unit(Hz)), y];

c3cosx+2sin0.4yHz,sinx2cos0.4yHz,y

(11)

c4 := [cos(x) - 2*sin(0.4*y*Unit(Hz)), sin(x) + 2*cos(0.4*y*Unit(Hz)), y];

c4cosx2sin0.4yHz,sinx+2cos0.4yHz,y

(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);

acceleration2ms2

(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));

expr0t<2st2s2ms2t<3s2t52sms2sotherwise

(14)

combine(eval(expr, t = 2200*Unit(ms)), units);

125m

(15)

combine(eval(expr, t = 0.5*Unit(min)), units);

55.00000000m

(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));

y__slope0.50076xx<33.948m17motherwise

(17)

y__fail := evalf(50*Unit(m) - sqrt(2401*Unit(m^2) - x^2));

y__fail50.m1.2401.m21.x2

(18)

rho := 20000*Unit(N/m^3);

ρ20000Nm3

(19)

x__max := 4*sqrt(82)*Unit(m);

x__max482m

(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.