Trigonometric functions: Difference between revisions

Content added Content deleted
m (→‎{{header|J}}: word fiddling)
(→‎{{header|J}}: Reworded commentary; omitted bad count. Changed naming of >@,: and 1&o.)
Line 62: Line 62:


=={{header|J}}==
=={{header|J}}==
Of the 24 [http://www.jsoftware.com/help/dictionary/dodot.htm circle functions] natively provided in J, six are used here. The same program is presented twice, first using only primaries, then using named definitions for components.
The [http://www.jsoftware.com/help/dictionary/dodot.htm circle functions] in J include trigonometric functions. 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
>,:(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 -------------
NB. ------------- program above is equivalent to program below -------------
sin =: 1&o.
sine =: 1&o.
cosine =: 2&o.
cosine =: 2&o.
tangent =: 3&o.
tangent =: 3&o.
Line 73: Line 73:
arctan =: _3&o.
arctan =: _3&o.
reorder=: >@,: NB. So output is like other examples
columns=: >@,: NB. Arrange output to look like other examples
rfd=: 180 %~ o. NB. Radians from degrees
rfd=: 180 %~ o. NB. Radians from degrees
AD=: 45 NB. Angle, in degrees
AD=: 45 NB. Angle, in degrees
AR=: (o. 1)%4 NB. Same angle, in radians (pi divided by four)
AR=: (o. 1)%4 NB. Same angle, in radians (pi divided by four)
reorder (sin; cosine; tangent; arcsin; arccos; arctan) AR, rfd AD
columns (sine; cosine; tangent; arcsin; arccos; arctan) AR, rfd AD
Output (from either version of the program):
Output (from either version of the program):
0.707107 0.707107
0.707107 0.707107