# Quantity and Trig functions

I have a bunch of data to which I've assigned units using Quantity, including some angular measurements in degrees. I'd like to be able to use these measurements with trigonometric functions, but it seems that trig functions don't "know" about Quantity, so I'm forced to convert those measurements to radians and then apply the trig function to the magnitudes, like this:

x = Quantity[23.4, "AngularDegrees"]


This works, but it's slow and seems clunky, at best. Is there a more elegant (and hopefully faster) approach?

• What happens if you try x /. Quantity[a_, "AngularDegrees"] :> a °? – J. M.'s torpor Apr 20 '13 at 1:27
• Have you tried using N? – Spawn1701D Apr 20 '13 at 1:40
• @J.M.: That's certainly faster--more than an order of magnitude in my quick check. – Cassini Apr 20 '13 at 3:36
• @Spawn1701D: How would I use N? – Cassini Apr 20 '13 at 3:36
• I don't have installed v9 yet so I can't verified it directly but i was thinking of something like N[Cos[x]]. – Spawn1701D Apr 20 '13 at 3:48

As noted in the comments, one might consider avoiding UnitConvert[] for this purpose:

lp = LatitudeLongitude[GeoPosition[{40.11, -88.26}]]
{Quantity[40.11, "AngularDegrees"], Quantity[-88.26, "AngularDegrees"]}

RepeatedTiming[lp /. Quantity[x_?NumericQ, "AngularDegrees"] :> x °]
{0.000013, {0.700052, -1.54043}}


For converting angles in DMS format, the method is a bit more elaborate:

sp = StarData["Polaris", "Declination"]
Quantity[MixedMagnitude[{89, 15, 50.762.1985422820612186}],
MixedUnit[{"AngularDegrees", "ArcMinutes", "ArcSeconds"}]]

sp /. Quantity[MixedMagnitude[m_],
MixedUnit[{"AngularDegrees", "ArcMinutes", "ArcSeconds"}]] :> FromDMS[m] °
1.55795


Despite the complexity, this is still faster than UnitConvert[]`.