# sandbox-maxima-worked-example-3

Before we get started, load ezunits.

load (ezunits);

 /usr/local/share/maxima/branch_5_32_base_2_g0e99686/share/ezunits/ezunits.mac

## 1 Units in integrals and derivatives

### 1.1 Integral

Units for integrals and derivatives are derived as the same units that a finite approximation would yield. Turn off simplification for a moment so that we can have a look at the unsimplified form.

simp : false $foo : 'integrate ((3 * t^2)  m/s, t  s, 0  s, t  s);   $\int_{0\;\mathrm{s}}^{t_{1}\;\mathrm{s}}{3\,t^{2}\;{{\mathrm{m}}\over{\mathrm{% s}}}\;dt\;\mathrm{s}}$ Now go ahead and simplify it. simp : true$
foo : ''foo;

 $3\,\left(\int_{0}^{t_{1}}{t^{2}\;dt}\right)\;\mathrm{m}$
%, nouns;

 $t_{1}^{3}\;\mathrm{m}$

### 1.2 Derivative

Again, have a look at the unsimplified form.

simp : false $foo : 'diff (sqrt (t)  inch, t  year, 1);   ${{d+^{1}}\over{d\,^{1}\left(t,{\it year}\right)}}\,\left(\sqrt{t}\;\mathrm{% inch}\right)$ Go ahead and simplify it. simp : true$
foo : ''foo;

 ${{d}\over{d\,t}}\,\sqrt{t}\;{{\mathrm{inch}}\over{\mathrm{year}}}$
foo, nouns;

 ${{1}\over{2\,\sqrt{t}}}\;{{\mathrm{inch}}\over{\mathrm{year}}}$

## 2 Units in solving equations

‘solve_dimensional’ can solve equations in which unit-ful expressions contain unknowns.

foo : solve_dimensional (10^6  Btu = 1/2 * (10  lbm) * v^2, v);

 $\left[v=\left(-8\,5^{{{5}\over{2}}}\right)\;{{\sqrt{\mathrm{Btu}}}\over{\sqrt{% \mathrm{lbm}}}},v=8\,5^{{{5}\over{2}}}\;{{\sqrt{\mathrm{Btu}}}\over{\sqrt{% \mathrm{lbm}}}}\right]$
dimensions (foo);

 $\left[{\it dimensions}\left(v\right)={{{\it length}}\over{{\it time}}},{\it dimensions% }\left(v\right)={{{\it length}}\over{{\it time}}}\right]$
foo1 : foo  m/s;

 $\left[{\it}\left(v,{{m}\over{s}}\right)=\left(-{{128\,5^{{{13}\over{2}}}\,% \sqrt{1055}}\over{\sqrt{45359237}}}\right)\;{{\mathrm{m}}\over{\mathrm{s}}},{% \it}\left(v,{{m}\over{s}}\right)={{128\,5^{{{13}\over{2}}}\,\sqrt{1055}}% \over{\sqrt{45359237}}}\;{{\mathrm{m}}\over{\mathrm{s}}}\right]$
float (foo1);

 $\left[{\it}\left(v,{{m}\over{s}}\right)=\left(-21567.92463845541\right)\;{{% \mathrm{m}}\over{\mathrm{s}}},{\it}\left(v,{{m}\over{s}}\right)=21567.924638% 45541\;{{\mathrm{m}}\over{\mathrm{s}}}\right]$

## 3 Selecting a named field from a unit-ful expression

‘@’ distributes over unit-ful expressions.

defstruct (my3d (x, y, z));

 $\left[{\it my3d}\left(x,y,z\right)\right]$
foo : my3d (17, 29, 42)  m;

 ${\it my3d}\left(17,29,42\right)\;\mathrm{m}$
foo @ z;

 $@\left({\it my3d}\left(17,29,42\right),z\right)\;\mathrm{m}$

Hmm, looks like it needs a little encouragement.

''%;

 $42\;\mathrm{m}$

## 4 Real part and imaginary part of a unit-ful expression

Simplifications for unit-ful expressions apply only to noun forms of ‘realpart’ and ‘imagpart’. Oh well.

declare (a, complex) \$
realpart (a  m);

 ${\it realpart}\left(a\;\mathrm{m}\right)$
''%;

 ${\it realpart}\left(a\right)\;\mathrm{m}$
imagpart (a  m);

 ${\it imagpart}\left(a\;\mathrm{m}\right)$
''%;

 ${\it imagpart}\left(a\right)\;\mathrm{m}$

## 5 Splitting off units of varying magnitudes

This one is for converting to units which come in conventional magnitude order, such as hours, minutes, and seconds, or miles, feet, and inches. When the units are specified as a list, the unit conversion operator will split off the first, then the second from the remainder of the first, the third from the remainder, etc.

10  km  mile;

 ${{78125}\over{12573}}\;\mathrm{mile}$
10  km  [mile, yard, foot, inch];

 $\left[6\;\mathrm{mile},376\;\mathrm{yard},0\;\mathrm{foot},{{608}\over{127}}\;% \mathrm{inch}\right]$
apply ("+", %)  km;

 $10\;\mathrm{km}$
Title sandbox-maxima-worked-example-3 Sandboxmaximaworkedexample3 2014-12-30 17:48:15 2014-12-30 17:48:15 robert_dodier (1000903) robert_dodier (1000903) 1 robert_dodier (1000903) Example