# How can I teach Maxima to use units?

I want to do engineering and scientific calculations im Maxima/wxmaxima. I do not want to manually check every time if my units make sense, how can I achieve this?

I'm looking at Maxima because it's free and solves equations etc. symbolically if asked.

• I remembered this Question when a friend posted about Frink, a new programming language/calculator (available on PCs and Android) that does track units through arbitrary precision calculations. It's also free! Nov 18 '13 at 15:03
• Unfortunately it seems there are many different ways to do this. I'd love to see a summary and comparison of pros and cons of each Apr 15 '17 at 16:26

I haven't used any of the following packages but they seem to be what you are looking for:

http://maxima.sourceforge.net/docs/manual/en/maxima_51.html#SEC257

http://maxima.sourceforge.net/docs/manual/en/maxima_79.html#SEC369

There is also dimension package by Barton Willis. It is most likely already a part of your maxima installation.

http://sourceforge.net/p/maxima/code/ci/master/tree/share/physics

A direct link to a pdf file with documentation:

http://sourceforge.net/p/maxima/code/ci/master/tree/share/physics/dimension.pdf?format=raw

You may find this example useful

  load("dimension");
depends(v, [t, x]);
depends(p, [t, x]);
/* put known dimensions */
qput(rho, mass/length^3, dimension);
qput(v, length/time, dimension);
qput(t, time, dimension);
qput(x, length, dimension);
qput(L, length, dimension);

/* Navier-Stokes equation */
ns: rho*(diff(v, t) + v*diff(v, x)) = -diff(p, x) + mu*diff(v, x, 2);

/* assume dimensions for p' and mu' are unknown and derive them */
eq1: dimension(lhs(ns)) = dimension(part(rhs(ns), 1));
eq2: dimension(lhs(ns)) = dimension(part(rhs(ns), 2));
sol: solve([eq1, eq2], [dimension(p), dimension(mu)])[1];

/* this line should give an error becouse ns' is dimensionally inconsistent */
/* dimension(ns); */

/* put dimensions for p' and mu'  */
put(p, assoc(dimension(p), sol),   'dimension);
put(mu, assoc(dimension(mu), sol), 'dimension);

/* now it is OK */
dimension(ns);

/* define Reynolds number as dimensionless reverse viscosity */
one_over_mu_unit: natural_unit(1/mu, [L, rho, v]);
Re: (1/mu)/one_over_mu_unit;

print("dimension(mu):          ", dimension(mu));
print("dimension(p):          ", dimension(p));
print("Reynolds number:        ", Re);
print("dimension(ns):        ",   dimension(ns));


The output should be:

                            mass
dimension(mu):           -----------
length time
mass
dimension(p):           ------------
2
length time
rho v L
Reynolds number:         [-------]
mu
mass
dimension(ns):         -------------
2     2
length  time


I also wanted to find a means of undertaking convenient calculations using wxMaxima, and finally came up with a very simple fix that enables me to undertake engineering calculations using any combinations of units, hybrid imperial, US customary, or SI, etc all within the body of the same calculation worksheet.
The fix is to batchload a units conversion file at the outset of the worksheet. i.e.

(%i1) batchload("/*path*/mks_UNITS_CONVERSION.wxm")

mks_UNITS_CONVERSION.wxm
"MKSK system conversion factors.

LENGTH
> m:1;
mm:.001;
cm:.01;
km:1000;
ins:25.4*mm;
ft:0.3048;
feet:ft;
yards:yd:36*ins;
mile:1609.344;
NM:1852;
`