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.Fri, 08 Jan 2016 12:42:25 +0100Calculate cosine in degreeshttps://ask.sagemath.org/question/32093/calculate-cosine-in-degrees/I'd like to calculate the value of the cosine of 52 degrees. The following fails:
lam = 52 * sage.units.degree
cos(lam)
How should I do it correctly?Wed, 06 Jan 2016 14:50:53 +0100https://ask.sagemath.org/question/32093/calculate-cosine-in-degrees/Answer by vdelecroix for <p>I'd like to calculate the value of the cosine of 52 degrees. The following fails:</p>
<pre><code>lam = 52 * sage.units.degree
cos(lam)
</code></pre>
<p>How should I do it correctly?</p>
https://ask.sagemath.org/question/32093/calculate-cosine-in-degrees/?answer=32096#post-id-32096A degree is easily converted in radian (360° versus $2\pi$)
sage: cos(52 / 360 * (2*pi))
cos(13/45*pi)
While this is perfectly correct, this is not very useful. In order to get a numerical approximation you can do
sage: c = cos(52 / 360 * (2*pi))
sage: c.numerical_approx()
0.615661475325658Wed, 06 Jan 2016 16:30:12 +0100https://ask.sagemath.org/question/32093/calculate-cosine-in-degrees/?answer=32096#post-id-32096Comment by kcrisman for <p>A degree is easily converted in radian (360° versus $2\pi$)</p>
<pre><code>sage: cos(52 / 360 * (2*pi))
cos(13/45*pi)
</code></pre>
<p>While this is perfectly correct, this is not very useful. In order to get a numerical approximation you can do</p>
<pre><code>sage: c = cos(52 / 360 * (2*pi))
sage: c.numerical_approx()
0.615661475325658
</code></pre>
https://ask.sagemath.org/question/32093/calculate-cosine-in-degrees/?comment=32098#post-id-32098Nice, though I do think it would be useful for Sage to auto-convert when the units are actually given.Thu, 07 Jan 2016 15:23:09 +0100https://ask.sagemath.org/question/32093/calculate-cosine-in-degrees/?comment=32098#post-id-32098Comment by vdelecroix for <p>A degree is easily converted in radian (360° versus $2\pi$)</p>
<pre><code>sage: cos(52 / 360 * (2*pi))
cos(13/45*pi)
</code></pre>
<p>While this is perfectly correct, this is not very useful. In order to get a numerical approximation you can do</p>
<pre><code>sage: c = cos(52 / 360 * (2*pi))
sage: c.numerical_approx()
0.615661475325658
</code></pre>
https://ask.sagemath.org/question/32093/calculate-cosine-in-degrees/?comment=32100#post-id-32100@kcrisman: I agree with you but there is no such module as sage.unitsThu, 07 Jan 2016 15:33:31 +0100https://ask.sagemath.org/question/32093/calculate-cosine-in-degrees/?comment=32100#post-id-32100Comment by vdelecroix for <p>A degree is easily converted in radian (360° versus $2\pi$)</p>
<pre><code>sage: cos(52 / 360 * (2*pi))
cos(13/45*pi)
</code></pre>
<p>While this is perfectly correct, this is not very useful. In order to get a numerical approximation you can do</p>
<pre><code>sage: c = cos(52 / 360 * (2*pi))
sage: c.numerical_approx()
0.615661475325658
</code></pre>
https://ask.sagemath.org/question/32093/calculate-cosine-in-degrees/?comment=32112#post-id-32112Right. Then it is `units.angles.degree` and `units.angles.radian` which ends up in error in evaluations
sage: s = 2 * units.angles.radian
sage: s.cos()
cos(2*radian)
sage: _.n()
Traceback (most recent call last):
...
TypeError: cannot evaluate symbolic expression numericallyFri, 08 Jan 2016 12:42:25 +0100https://ask.sagemath.org/question/32093/calculate-cosine-in-degrees/?comment=32112#post-id-32112Comment by kcrisman for <p>A degree is easily converted in radian (360° versus $2\pi$)</p>
<pre><code>sage: cos(52 / 360 * (2*pi))
cos(13/45*pi)
</code></pre>
<p>While this is perfectly correct, this is not very useful. In order to get a numerical approximation you can do</p>
<pre><code>sage: c = cos(52 / 360 * (2*pi))
sage: c.numerical_approx()
0.615661475325658
</code></pre>
https://ask.sagemath.org/question/32093/calculate-cosine-in-degrees/?comment=32111#post-id-32111Perhaps the OP was using http://doc.sagemath.org/html/en/reference/calculus/sage/symbolic/units.html ?Fri, 08 Jan 2016 07:12:45 +0100https://ask.sagemath.org/question/32093/calculate-cosine-in-degrees/?comment=32111#post-id-32111