Trigonometric functions: Difference between revisions
Content added Content deleted
(Added a bit about a difference in behavior for inverse functions) |
(→{{header|J}}: Changed inverse functions to match clarified requirements.) |
||
Line 91: | Line 91: | ||
=={{header|J}}== |
=={{header|J}}== |
||
The [http://www.jsoftware.com/help/dictionary/dodot.htm circle functions] in J include trigonometric functions. |
The [http://www.jsoftware.com/help/dictionary/dodot.htm circle functions] in J include trigonometric functions. Native operation is in radians, so results in degrees involves conversion. |
||
Sine, cosine, and tangent of 45 degrees |
|||
Here the same program is presented twice, first using only primaries, then using named definitions for components. |
|||
>,:(1&o. ; 2&o. ; 3 |
>,:(1&o. ; 2&o. ; 3&o.) (4%~o. 1), 180 %~ o. 45 |
||
NB. ------------- program above is equivalent to program below ------------- |
|||
sine =: 1&o. |
|||
cosine =: 2&o. |
|||
tangent =: 3&o. |
|||
arcsin =: _1&o. |
|||
arccos =: _2&o. |
|||
arctan =: _3&o. |
|||
columns=: >@,: NB. Arrange output to look like other examples |
|||
rfd=: 180 %~ o. NB. Radians from degrees |
|||
AD=: 45 NB. Angle, in degrees |
|||
AR=: (o. 1)%4 NB. Same angle, in radians (pi divided by four) |
|||
columns (sine; cosine; tangent; arcsin; arccos; arctan) AR, rfd AD |
|||
Output (from either version of the program): |
|||
0.707107 0.707107 |
0.707107 0.707107 |
||
0.707107 0.707107 |
0.707107 0.707107 |
||
1 1 |
1 1 |
||
Arcsine, arccosine, and arctangent of 0.5 |
|||
0.903339 0.903339 |
|||
>,:([ , 180p_1&*)&.> (_1&o. ; _2&o. ; _3&o.) 0.5 |
|||
0.667457 0.667457 |
|||
0. |
0.523599 30 |
||
1.0472 60 |
|||
0.463648 26.5651 |
|||
=={{header|Java}}== |
=={{header|Java}}== |