This commit is contained in:
Ingy döt Net 2013-10-27 22:24:23 +00:00
parent 6f050a029e
commit 776bba907c
3887 changed files with 59894 additions and 7280 deletions

View file

@ -1,2 +1 @@
{{omit from|GAP}}
If your language has a library or built-in functions for trigonometry, show examples of sine, cosine, tangent, and their inverses using the same angle in radians and degrees. For the non-inverse functions, each radian/degree pair should use arguments that evaluate to the same angle (that is, it's not necessary to use the same angle for all three regular functions as long as the two sine calls use the same angle). For the inverse functions, use the same number and convert its answer to radians and degrees. If your language does not have trigonometric functions available or only has some available, write functions to calculate the functions based on any [[wp:List of trigonometric identities|known approximation or identity]].

View file

@ -0,0 +1,39 @@
IDENTIFICATION DIVISION.
PROGRAM-ID. Trig.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 Pi-Third USAGE COMP-2.
01 Degree USAGE COMP-2.
01 60-Degrees USAGE COMP-2.
01 Result USAGE COMP-2.
PROCEDURE DIVISION.
COMPUTE Pi-Third = FUNCTION PI / 3
DISPLAY "Radians:"
DISPLAY " Sin(π / 3) = " FUNCTION SIN(Pi-Third)
DISPLAY " Cos(π / 3) = " FUNCTION COS(Pi-Third)
DISPLAY " Tan(π / 3) = " FUNCTION TAN(Pi-Third)
DISPLAY " Asin(0.5) = " FUNCTION ASIN(0.5)
DISPLAY " Acos(0.5) = " FUNCTION ACOS(0.5)
DISPLAY " Atan(0.5) = " FUNCTION ATAN(0.5)
COMPUTE Degree = FUNCTION PI / 180
COMPUTE 60-Degrees = Degree * 60
DISPLAY "Degrees:"
DISPLAY " Sin(60°) = " FUNCTION SIN(60-Degrees)
DISPLAY " Cos(60°) = " FUNCTION COS(60-Degrees)
DISPLAY " Tan(60°) = " FUNCTION TAN(60-Degrees)
COMPUTE Result = FUNCTION ASIN(0.5) / 60
DISPLAY " Asin(0.5) = " Result
COMPUTE Result = FUNCTION ACOS(0.5) / 60
DISPLAY " Acos(0.5) = " Result
COMPUTE Result = FUNCTION ATAN(0.5) / 60
DISPLAY " Atan(0.5) = " Result
GOBACK
.

View file

@ -0,0 +1,15 @@
# GAP has an improved floating-point support since version 4.5
Pi := Acos(-1.0);
r := Pi / 5.0;
d := 36;
Deg := x -> x * Pi / 180;
Sin(r); Asin(last);
Sin(Deg(d)); Asin(last);
Cos(r); Acos(last);
Cos(Deg(d)); Acos(last);
Tan(r); Atan(last);
Tan(Deg(d)); Atan(last);

View file

@ -0,0 +1,14 @@
:- object(trignomeric_functions).
:- public(show/0).
show :-
% standard trignomeric functions work with radians
write('sin(pi/4.0) = '), SIN is sin(pi/4.0), write(SIN), nl,
write('cos(pi/4.0) = '), COS is cos(pi/4.0), write(COS), nl,
write('tan(pi/4.0) = '), TAN is tan(pi/4.0), write(TAN), nl,
write('asin(sin(pi/4.0)) = '), ASIN is asin(sin(pi/4.0)), write(ASIN), nl,
write('acos(cos(pi/4.0)) = '), ACOS is acos(cos(pi/4.0)), write(ACOS), nl,
write('atan(tan(pi/4.0)) = '), ATAN is atan(tan(pi/4.0)), write(ATAN), nl,
write('atan2(3,4) = '), ATAN2 is atan2(3,4), write(ATAN2), nl.
:- end_object.

View file

@ -0,0 +1,9 @@
?- trignomeric_functions::show.
sin(pi/4.0) = 0.7071067811865475
cos(pi/4.0) = 0.7071067811865476
tan(pi/4.0) = 0.9999999999999999
asin(sin(pi/4.0)) = 0.7853981633974482
acos(cos(pi/4.0)) = 0.7853981633974483
atan(tan(pi/4.0)) = 0.7853981633974483
atan2(3,4) = 0.6435011087932844
yes

View file

@ -0,0 +1,18 @@
#lang racket
(define radians (/ pi 4))
(define degrees 45)
(displayln (format "~a ~a" (sin radians) (sin (* degrees (/ pi 180)))))
(displayln (format "~a ~a" (cos radians) (cos (* degrees (/ pi 180)))))
(displayln (format "~a ~a" (tan radians) (tan (* degrees (/ pi 180)))))
(define arcsin (asin (sin radians)))
(displayln (format "~a ~a" arcsin (* arcsin (/ 180 pi))))
(define arccos (acos (cos radians)))
(displayln (format "~a ~a" arccos (* arccos (/ 180 pi))))
(define arctan (atan (tan radians)))
(display (format "~a ~a" arctan (* arctan (/ 180 pi))))