ezunits and solve



On 2012-10-29, Thorsten Bonow <thorsten.bonow at withouthat.org> wrote:

> I'm trying to use "ezunits" to do some calculations, but when using units,
> "solve" looses its capability of solving even simple equations.

It's late in the game, but for the record, I have beefed up ezunits
with new function solve_dimensional which can solve some equations
involving units. (It is a new function because there isn't an easy way
to intercept calls to the built-in solve function.) The new function
reformulates the problem, calls the built-in solve, then rebuilds any
units expressions.

The current version is committed to the master branch, so it will appear
in the 5.30 release (not Maxima 5.29).

Here are a couple of examples from the mailing list.

  load (ezunits);
  [a, c, d] : [1 ` m, 2 ` m, 3 ` m];
  solve_dimensional ([A = a * b, b = c * d], [A, b]);
    => [[A = 6 ` m^3,b = 6 ` m^2]]

  solve_dimensional (x ` m = 5 ` ft, x);
    => [x = 5 ` ft/m]
  dimensions (%);
    => ['dimensions(x) = 1]
  %th(2) `` 1;
    => [x = 381/250]
 

A quadratic equation.

  solve_dimensional (10^6 ` Btu = 1/2 * (10 ` lbm) * v^2, v);
   => [v = (-8*5^(5/2)) ` sqrt(Btu)/sqrt(lbm),v = 8*5^(5/2) ` sqrt(Btu)/sqrt(lbm)]
  dimensions (%);
   => ['dimensions(v) = length/time,'dimensions(v) = length/time]
  %th(2) `` m/s;
   => [v `` m/s = (-128*5^(13/2)*sqrt(1055)/sqrt(45359237)) ` m/s,
        v `` m/s = 128*5^(13/2)*sqrt(1055)/sqrt(45359237) ` m/s]
  float (%);
   => [v `` m/s = (-21567.92463845543) ` m/s,v `` m/s = 21567.92463845543 ` m/s]


An example involving symbolic constants (Planck's and speed of light).

  load (physical_constants);
  declare ([E, %lambda], dimensional);
  eq : E * %lambda = %c * %h;
  solve_dimensional (eq, %lambda), E = 10^-20 ` J;
   => [%lambda = %c*%h*(100000000000000000000 ` 1/J)]
  dimensions (%);
   => ['dimensions(%lambda) = length]
  %th(2), constvalue;
   => [%lambda = 6207642188737199/312500000000000000000 ` m]
  float (%);
   => [%lambda = 1.986445500395904E-5 ` m]


Anyway perhaps this is useful in some way.

best

Robert Dodier