I have received a couple of helpful hints about functional existing open source packages that treat units in the desired way (ezunits in maxima and DesignerUnits.com), but I am still after the quick and dirty way for using the existing units package in sage. The only thing that really stops me right now is that I don't know how to get it to return: units.x.y + units.x.y = units.x.y units.x.y - units.x.y = units.x.y
Is there an easy way to write a function that would do that while keeping the rest (multiplication, division, exponents etc.) the way it is? Thanks again for your help! On Aug 3, 1:55 pm, Stan Schymanski <schym...@gmail.com> wrote: > The division by zero is not the issue here, but the disappearance of > theunitswhen two variables with the sameunitsare subtracted from > each other. Wolfram gives 0 K for (kelvin - > kelvin):http://www.wolframalpha.com/input/?i=%28kelvin+-+kelvin%29 > > Sage would simply give 0 without anyunits, so that multiplication > with the term (kelvin-kelvin) would give 0, too. Nounits. > > The function for a dimensional analysis without coefficients sounds > like a great idea. If you could post something quick and dirty, I > could see a bit better what you mean. Thanks for thinking about it, > anyway! > > Stan > > On Aug 3, 12:21 pm, Eviatar <eviatarb...@gmail.com> wrote: > > > > > > > > > I don't think there is an easy way. > > > It seems that in Mathematica division by zero does not return an > > error, simply evaluates to infinity (http://www.wolframalpha.com/ > > input/?i=1%2F0), which only makes sense if you are using the limit > > definition of equality. > > > So essentially, the way to fix this in Sage would be to haveunitsbe > > "special" symbolic variables when evaluating limits, so that > > > sage: limit(1 / x, x=units.length.meter.mul(0, hold=True)) > > Infinity > > > would return Infinity*meter instead. I think this would be quite hard > > to do. > > > The other option would be to operator overload the UnitExpression > > class or modify the behaviour of symbolic variables when they are > > detected to beunits. In any case, dividing by zero would still return > > an error. > > > Maybe it would be useful to have a function that just does dimensional > > analysis and ignores coefficients? This wouldn't be hard to write. > > > On Aug 3, 12:40 am, Stan Schymanski <schym...@gmail.com> wrote: > > > > Yes, this makes sense to me. Wolfram seems to treat the expression and > > > theunitsseparately, which makes sense. In your example, any omitted > > > value is seen as 1, so the result is perfectly correct. The expression > > > is evaluated and theunitsare added after it, but they don't cancel > > > out by subtraction. I don't think it is sensible to treatunitsas > > > variables if this leads to results like the one I encountered. Then > > > nothing is gained by using theunitspackage and I could just create > > > my own variables called m, K, J, W etc. Is there an easy way to get a > > > behaviour like in Mathematica? > > > > On Aug 2, 9:29 pm, Eviatar <eviatarb...@gmail.com> wrote: > > > > > It seems WolframAlpha evaluates the limit of the > > > > expression:http://www.wolframalpha.com/input/?i=%28calorie%2Fcentimeter%5E2%2F+m.... > > > > > On Aug 2, 12:21 pm, Eviatar <eviatarb...@gmail.com> wrote: > > > > > > I don't really see this as a bug.Unitsare treated as variables, so > > > > > it makes sense. Are you suggesting that 0 * kelvin should be left > > > > > unevaluated, and then not give an error when it is the denominator? > > > > > > On Aug 2, 7:49 am, Stan Schymanski <schym...@gmail.com> wrote: > > > > > > > Dear all, > > > > > > > This is a bug-report or feature request for theunitspackage, taken > > > > > > from sage-support. Basically, theunitspackage does not handle > > > > > > addition and subtraction in a sensible way, asunitscancel out when > > > > > > variables with the sameunitsare subtracted from each other. Sage > > > > > > should give an error message when adding or subtracting variables > > > > > > with > > > > > > differentunits, while leaving theunitsintact if the variables have > > > > > > the sameunits. Does anyone have an idea how this could be > > > > > > accomplished? Thanks already! > > > > > > > Below is an example of the problem posted > > > > > > athttp://groups.google.com/group/sage-support/browse_thread/thread/a60c... > > > > > > > sage: udict = {} > > > > > > sage: udict[H_l] =units.energy.calorie/units.length.centimeter^2/ > > > > > >units.time.minute > > > > > > sage: udict[T_a] =units.temperature.kelvin > > > > > > sage: udict[T_l] =units.temperature.kelvin > > > > > > sage: soln = solve(H_l == h_c*(T_a - T_l), h_c)[0]; soln > > > > > > h_c == H_l/(T_a - T_l) > > > > > > sage: soln.subs(udict) > > > > > > Traceback (most recent call last): > > > > > > ... > > > > > > RuntimeError: power::eval(): division by zero > > > > > > > --- > > > > > > This works: > > > > > > sage: (H_l/T_a).subs(udict) > > > > > > calorie/(centimeter^2*kelvin*minute) -- 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