Ask Your Question
1

Calculate cosine in degrees

asked 2016-01-06 14:50:53 +0200

marmistrz gravatar image

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?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2016-01-06 16:30:12 +0200

vdelecroix gravatar image

updated 2016-01-06 18:05:50 +0200

A 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.615661475325658
edit flag offensive delete link more

Comments

1

Nice, though I do think it would be useful for Sage to auto-convert when the units are actually given.

kcrisman gravatar imagekcrisman ( 2016-01-07 15:23:09 +0200 )edit

@kcrisman: I agree with you but there is no such module as sage.units

vdelecroix gravatar imagevdelecroix ( 2016-01-07 15:33:31 +0200 )edit

Perhaps the OP was using http://doc.sagemath.org/html/en/refer... ?

kcrisman gravatar imagekcrisman ( 2016-01-08 07:12:45 +0200 )edit

Right. 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 numerically
vdelecroix gravatar imagevdelecroix ( 2016-01-08 12:42:25 +0200 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2016-01-06 14:50:53 +0200

Seen: 2,394 times

Last updated: Jan 06 '16