Question: How to work with functions that contain units inside?

I'd like to be able to define functions with units and then use them.

In the example below, things don't work with Maple input. I've shown one example, with the function f2.

It seems to work better with 2D input, but it seems that it is not possible to make plots.

In the example below, I define f4 as a function of two variables that returns a function of one variable.

I'd like to call the outer function, obtain a function as a result (r1 below) and then plot the latter.

restart

with(Units:-Simple)

NULL

f1 := proc (x) options operator, arrow; x*Unit('m') end proc

proc (x) options operator, arrow; Units:-Simple:-`*`(x, Unit('m')) end proc

(1)

f1(2)

2*Units:-Unit(m)

(2)

f2:=x->xUnit(m)

Units:-Unit(m)

(3)

f2(2)

f2(2)

(4)

f3 := proc (x, y) options operator, arrow; x*Unit('m')*y*Unit('m') end proc

proc (x, y) options operator, arrow; Units:-Simple:-`*`(Units:-Simple:-`*`(Units:-Simple:-`*`(x, Unit('m')), y), Unit('m')) end proc

(5)

f3(2, 3)

6*Units:-Unit(m^2)

(6)

f4 := proc (x, y) options operator, arrow; proc (z) options operator, arrow; x*Unit('m')*y*Unit('m')*z*Unit('m') end proc end proc

proc (x, y) options operator, arrow; proc (z) options operator, arrow; Units:-Simple:-`*`(Units:-Simple:-`*`(Units:-Simple:-`*`(Units:-Simple:-`*`(Units:-Simple:-`*`(x, Unit('m')), y), Unit('m')), z), Unit('m')) end proc end proc

(7)

r1 := f4(2, 3)

proc (z) options operator, arrow; Units:-Simple:-`*`(Units:-Simple:-`*`(Units:-Simple:-`*`(Units:-Simple:-`*`(Units:-Simple:-`*`(2, Unit('m')), 3), Unit('m')), z), Unit('m')) end proc

(8)

r1(4)

24*Units:-Unit(m^3)

(9)

plot(r1)

 

NULL

The contents above aren't showing the error that Maple gives when I try to plot.

Here is a screenshot

Download FunctionUnits.mw

Please Wait...