Jump to content

Trigonometric functions: Difference between revisions

→‎{{header|J}}: Changed inverse functions to match clarified requirements.
(Added a bit about a difference in behavior for inverse functions)
(→‎{{header|J}}: Changed inverse functions to match clarified requirements.)
Line 91:
 
=={{header|J}}==
The [http://www.jsoftware.com/help/dictionary/dodot.htm circle functions] in J include trigonometric functions. TheyNative acceptoperation is in radians, so conversionresults fromin degrees isinvolves requiredconversion.
 
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&o. ; _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
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.665774523599 0.665774 30
1.0472 60
0.463648 26.5651
 
=={{header|Java}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.