Unfortunately, the original thread expired, so I have to start a new
one. Here is the original:
http://groups.google.com/group/sage-devel/browse_thread/thread/81884a53ab28212/58ad9417b01ed46f?lnk=gst&q=units#58ad9417b01ed46f
and some more ideas are here:
http://groups.google.com/group/sage-support/browse_thread/thread/a60c943c224dfe87/3d19ca65a82f2498?lnk=gst&q=units#3d19ca65a82f2498

Basically the problem was that I wanted to be able to check for
consistency of units in equations. I think that I have found a way,
but I am not sure if it will always work. Basicallly, I define a
dictionary with keys for all variables and their units multiplied by
the variable names:

var('T_a')
udict = {}
udict[T_a] = T_a*units.temperature.kelvin

Then, the following function will check whether all variables in an
expression are defined in udict, and then give the units of the
expression:

def units_check(eq):
    '''
    Checks whether all arguments are keys in udict and returns
simplified units
    '''
    for var1 in eq.arguments():
        udict[var1]
    return (eq.subs(udict1)/eq).simplify_full()

If eq is an equation, we can compare both sides, if it is just an
expression, inconsistency will show up in a form of a plus or minus in
the output.

Since the dictionary contains the variable multiplied by its units,
they do not cancel out by subtraction, so the problem discussed
previously should be avoided.

Cheers
Stan

-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org

Reply via email to