ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 13 May 2018 02:03:59 +0200Define custom unithttps://ask.sagemath.org/question/42321/define-custom-unit/ Is it possible to declare custom units that can be converted to SI base units? For example: if I want to measure time in ticks and I know that one tick is exactly one nanosecond, can I create a unit 'tick' that can later be converted to seconds?
I know that a custom unit can be declared with
sage: sage.symbolic.units.str_to_unit('tick')
tick
I also know that predefined units can be converted, for example by
sage: units.time.minute.convert(units.time.second)
60*second
However, I want to be able to declare a unit that has both its own name and that can be converted to other units.
sage: tick = sage.symbolic.units.str_to_unit('tick')
sage: tick
tick
sage: #(define relation to SI units here)
sage: tick.convert(units.time.second)
(ValueError: Incompatible units)
Is it possible to define a unit ‘tick’ that can be converted to seconds in this manner?johannehSun, 13 May 2018 02:03:59 +0200https://ask.sagemath.org/question/42321/Unit conversionhttps://ask.sagemath.org/question/9555/unit-conversion/I'm not certain if the behaviour is correct in this example, or I am possibly misunderstanding something. Sorry about the lengthy example, but I had difficulties simplifying it into a simpler one.
# Setup units
lbf = units.force.pound_force;
inch = units.length.inch;
sec = units.time.second;
psi = lbf / inch^2;
gal = 231.0*inch^3;
min = 60.0*sec;
gpm = gal/min;
hole = gpm/sqrt(psi);
# Define the given constraints
FLext = 20000.0*lbf;
vext = 15.0*inch/sec;
FLret = -10000.0*lbf;
vret = -15.0*inch/sec;
# Assumed values
Ps = 3000.0*psi;
pv = 1.0;
pc = 1.4;
# System of 3 equations, 3 unknowns
ABE = var('A_BE');
ARE = var('A_RE');
kv = var('k_v');
eq1 = vext^2 == (Ps*ABE - FLext) * kv^2 / ABE^3 / (1 + pv^2 * pc^(-3));
eq2 = vret^2 == (FLret + Ps*ARE) * kv^2 / ARE^3 / (1 + pv^2 * pc^3);
eq3 = pc == ABE / ARE;
sol = solve([eq1, eq2, eq3], [ABE, ARE, kv], solution_dict=True);
sol = sol[1];
show(sol[ABE])
show(sol[ARE])
show(sol[kv])
# Showing the units of various variables
show(sol[kv].convert())
show(hole.convert())
show( (sol[kv]/hole).convert() ) # this should be dimensionless
# Showing the potential bug with unit conversion
show(sol[kv].convert(hole)) # ValueError: Incompatible units
Running the code, the section labelled `# Showing the units of various variables`, you can see the various units of the relevant variables. The code for `show( (sol[kv]/hole).convert() )` should return a dimensionless value, however it still shows units in the result. Looking at the non-numeric portions of it, everything appears to cancel. Running `show(sol[kv].convert(hole))` results in `ValueError: Incompatible units`. I expected a conversion into gpm/sqrt(psi) (i.e. holes).
What concerns me is my calculator (TI-92+) has conversion difficulties with this unit as well, being unable to convert. Is this the expected/normal/ideal behaviour for sage? If so, for what reason(s)? If not, what should I do?
Thank you,
menturimenturi628Wed, 21 Nov 2012 20:06:03 +0100https://ask.sagemath.org/question/9555/Radiandegree conversionhttps://ask.sagemath.org/question/8210/radiandegree-conversion/Hello,
It seems to be unnecessarily hard to numerically convert radians to degrees in Sage. For example, how does one convert arctan(4/5) radians to degrees?
The following
<pre>n(arctan(4/5))*sage.symbolic.units.convert(units.angles.radian,units.angles.degree)</pre>
returns
<pre>121.453369600239*degree/pi</pre>
Is there a simple way to just return a numerical answer (without multiplying by 180/pi)?Eviatar BachMon, 04 Jul 2011 22:50:01 +0200https://ask.sagemath.org/question/8210/