Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
5
Task/Trigonometric-functions/00-META.yaml
Normal file
5
Task/Trigonometric-functions/00-META.yaml
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
category:
|
||||
- Mathematics
|
||||
from: http://rosettacode.org/wiki/Trigonometric_functions
|
||||
note: Arithmetic operations
|
||||
15
Task/Trigonometric-functions/00-TASK.txt
Normal file
15
Task/Trigonometric-functions/00-TASK.txt
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
;Task:
|
||||
If your language has a library or built-in functions for trigonometry, show examples of:
|
||||
::* sine
|
||||
::* cosine
|
||||
::* tangent
|
||||
::* inverses (of the above)
|
||||
<br>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]].
|
||||
<br><br>
|
||||
|
||||
11
Task/Trigonometric-functions/11l/trigonometric-functions.11l
Normal file
11
Task/Trigonometric-functions/11l/trigonometric-functions.11l
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
V rad = math:pi / 4
|
||||
V deg = 45.0
|
||||
print(‘Sine: ’sin(rad)‘ ’sin(radians(deg)))
|
||||
print(‘Cosine: ’cos(rad)‘ ’cos(radians(deg)))
|
||||
print(‘Tangent: ’tan(rad)‘ ’tan(radians(deg)))
|
||||
V arcsine = asin(sin(rad))
|
||||
print(‘Arcsine: ’arcsine‘ ’degrees(arcsine))
|
||||
V arccosine = acos(cos(rad))
|
||||
print(‘Arccosine: ’arccosine‘ ’degrees(arccosine))
|
||||
V arctangent = atan(tan(rad))
|
||||
print(‘Arctangent: ’arctangent‘ ’degrees(arctangent))
|
||||
|
|
@ -0,0 +1,79 @@
|
|||
(defun fac (n)
|
||||
(if (zp n)
|
||||
1
|
||||
(* n (fac (1- n)))))
|
||||
|
||||
(defconst *pi-approx*
|
||||
(/ 3141592653589793238462643383279
|
||||
(expt 10 30)))
|
||||
|
||||
(include-book "arithmetic-3/floor-mod/floor-mod" :dir :system)
|
||||
|
||||
(defun dgt-to-str (d)
|
||||
(case d
|
||||
(1 "1") (2 "2") (3 "3") (4 "4") (5 "5")
|
||||
(6 "6") (7 "7") (8 "8") (9 "9") (0 "0")))
|
||||
|
||||
(defmacro cat (&rest args)
|
||||
`(concatenate 'string ,@args))
|
||||
|
||||
(defun num-to-str-r (n)
|
||||
(if (zp n)
|
||||
""
|
||||
(cat (num-to-str-r (floor n 10))
|
||||
(dgt-to-str (mod n 10)))))
|
||||
|
||||
(defun num-to-str (n)
|
||||
(cond ((= n 0) "0")
|
||||
((< n 0) (cat "-" (num-to-str-r (- n))))
|
||||
(t (num-to-str-r n))))
|
||||
|
||||
(defun pad-with-zeros (places str lngth)
|
||||
(declare (xargs :measure (nfix (- places lngth))))
|
||||
(if (zp (- places lngth))
|
||||
str
|
||||
(pad-with-zeros places (cat "0" str) (1+ lngth))))
|
||||
|
||||
(defun as-decimal-str (r places)
|
||||
(let ((before (floor r 1))
|
||||
(after (floor (* (expt 10 places) (mod r 1)) 1)))
|
||||
(cat (num-to-str before)
|
||||
"."
|
||||
(let ((afterstr (num-to-str after)))
|
||||
(pad-with-zeros places afterstr
|
||||
(length afterstr))))))
|
||||
|
||||
(defun taylor-sine (theta terms term)
|
||||
(declare (xargs :measure (nfix (- terms term))))
|
||||
(if (zp (- terms term))
|
||||
0
|
||||
(+ (/ (*(expt -1 term) (expt theta (1+ (* 2 term))))
|
||||
(fac (1+ (* 2 term))))
|
||||
(taylor-sine theta terms (1+ term)))))
|
||||
|
||||
(defun sine (theta)
|
||||
(taylor-sine (mod theta (* 2 *pi-approx*))
|
||||
20 0)) ; About 30 places of accuracy
|
||||
|
||||
(defun cosine (theta)
|
||||
(sine (+ theta (/ *pi-approx* 2))))
|
||||
|
||||
(defun tangent (theta)
|
||||
(/ (sine theta) (cosine theta)))
|
||||
|
||||
(defun rad->deg (rad)
|
||||
(* 180 (/ rad *pi-approx*)))
|
||||
|
||||
(defun deg->rad (deg)
|
||||
(* *pi-approx* (/ deg 180)))
|
||||
|
||||
(defun trig-demo ()
|
||||
(progn$ (cw "sine of pi / 4 radians: ")
|
||||
(cw (as-decimal-str (sine (/ *pi-approx* 4)) 20))
|
||||
(cw "~%sine of 45 degrees: ")
|
||||
(cw (as-decimal-str (sine (deg->rad 45)) 20))
|
||||
(cw "~%cosine of pi / 4 radians: ")
|
||||
(cw (as-decimal-str (cosine (/ *pi-approx* 4)) 20))
|
||||
(cw "~%tangent of pi / 4 radians: ")
|
||||
(cw (as-decimal-str (tangent (/ *pi-approx* 4)) 20))
|
||||
(cw "~%")))
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
main:(
|
||||
REAL pi = 4 * arc tan(1);
|
||||
# Pi / 4 is 45 degrees. All answers should be the same. #
|
||||
REAL radians = pi / 4;
|
||||
REAL degrees = 45.0;
|
||||
REAL temp;
|
||||
# sine #
|
||||
print((sin(radians), " ", sin(degrees * pi / 180), new line));
|
||||
# cosine #
|
||||
print((cos(radians), " ", cos(degrees * pi / 180), new line));
|
||||
# tangent #
|
||||
print((tan(radians), " ", tan(degrees * pi / 180), new line));
|
||||
# arcsine #
|
||||
temp := arc sin(sin(radians));
|
||||
print((temp, " ", temp * 180 / pi, new line));
|
||||
# arccosine #
|
||||
temp := arc cos(cos(radians));
|
||||
print((temp, " ", temp * 180 / pi, new line));
|
||||
# arctangent #
|
||||
temp := arc tan(tan(radians));
|
||||
print((temp, " ", temp * 180 / pi, new line))
|
||||
)
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
begin
|
||||
% Algol W only supplies sin, cos and arctan as standard. We can define %
|
||||
% arcsin, arccos and tan functions using these. The standard functions %
|
||||
% use radians so we also provide versions that use degrees %
|
||||
|
||||
% convert degrees to radians %
|
||||
real procedure toRadians( real value x ) ; pi * ( x / 180 );
|
||||
% convert radians to degrees %
|
||||
real procedure toDegrees( real value x ) ; 180 * ( x / pi );
|
||||
% tan of an angle in radians %
|
||||
real procedure tan( real value x ) ; sin( x ) / cos( x );
|
||||
% arcsin in radians %
|
||||
real procedure arcsin( real value x ) ; arctan( x / sqrt( 1 - ( x * x ) ) );
|
||||
% arccos in radians %
|
||||
real procedure arccos( real value x ) ; arctan( sqrt( 1 - ( x * x ) ) / x );
|
||||
% sin of an angle in degrees %
|
||||
real procedure sinD( real value x ) ; sin( toRadians( x ) );
|
||||
% cos of an angle in degrees %
|
||||
real procedure cosD( real value x ) ; cos( toRadians( x ) );
|
||||
% tan of an angle in degrees %
|
||||
real procedure tanD( real value x ) ; tan( toRadians( x ) );
|
||||
% arctan in degrees %
|
||||
real procedure arctanD( real value x ) ; toDegrees( arctan( x ) );
|
||||
% arcsin in degrees %
|
||||
real procedure arcsinD( real value x ) ; toDegrees( arcsin( x ) );
|
||||
% arccos in degrees %
|
||||
real procedure arccosD( real value x ) ; toDegrees( arccos( x ) );
|
||||
|
||||
|
||||
% test the procedures %
|
||||
begin
|
||||
|
||||
real piOver4, piOver3, oneOverRoot2, root3Over2;
|
||||
piOver3 := pi / 3; piOver4 := pi / 4;
|
||||
oneOverRoot2 := 1.0 / sqrt( 2 ); root3Over2 := sqrt( 3 ) / 2;
|
||||
|
||||
|
||||
r_w := 12; r_d := 5; r_format := "A"; s_w := 0; % set output format %
|
||||
|
||||
write( "PI/4: ", piOver4, " 1/root(2): ", oneOverRoot2 );
|
||||
write();
|
||||
write( "sin 45 degrees: ", sinD( 45 ), " sin pi/4 radians: ", sin( piOver4 ) );
|
||||
write( "cos 45 degrees: ", cosD( 45 ), " cos pi/4 radians: ", cos( piOver4 ) );
|
||||
write( "tan 45 degrees: ", tanD( 45 ), " tan pi/4 radians: ", tan( piOver4 ) );
|
||||
write();
|
||||
write( "arcsin( sin( pi/4 radians ) ): ", arcsin( sin( piOver4 ) ) );
|
||||
write( "arccos( cos( pi/4 radians ) ): ", arccos( cos( piOver4 ) ) );
|
||||
write( "arctan( tan( pi/4 radians ) ): ", arctan( tan( piOver4 ) ) );
|
||||
write();
|
||||
write( "PI/3: ", piOver4, " root(3)/2: ", root3Over2 );
|
||||
write();
|
||||
write( "sin 60 degrees: ", sinD( 60 ), " sin pi/3 radians: ", sin( piOver3 ) );
|
||||
write( "cos 60 degrees: ", cosD( 60 ), " cos pi/3 radians: ", cos( piOver3 ) );
|
||||
write( "tan 60 degrees: ", tanD( 60 ), " tan pi/3 radians: ", tan( piOver3 ) );
|
||||
write();
|
||||
write( "arcsin( sin( 60 degrees ) ): ", arcsinD( sinD( 60 ) ) );
|
||||
write( "arccos( cos( 60 degrees ) ): ", arccosD( cosD( 60 ) ) );
|
||||
write( "arctan( tan( 60 degrees ) ): ", arctanD( tanD( 60 ) ) );
|
||||
|
||||
end
|
||||
|
||||
end.
|
||||
40
Task/Trigonometric-functions/AWK/trigonometric-functions.awk
Normal file
40
Task/Trigonometric-functions/AWK/trigonometric-functions.awk
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
# tan(x) = tangent of x
|
||||
function tan(x) {
|
||||
return sin(x) / cos(x)
|
||||
}
|
||||
|
||||
# asin(y) = arcsine of y, domain [-1, 1], range [-pi/2, pi/2]
|
||||
function asin(y) {
|
||||
return atan2(y, sqrt(1 - y * y))
|
||||
}
|
||||
|
||||
# acos(x) = arccosine of x, domain [-1, 1], range [0, pi]
|
||||
function acos(x) {
|
||||
return atan2(sqrt(1 - x * x), x)
|
||||
}
|
||||
|
||||
# atan(y) = arctangent of y, range (-pi/2, pi/2)
|
||||
function atan(y) {
|
||||
return atan2(y, 1)
|
||||
}
|
||||
|
||||
BEGIN {
|
||||
pi = atan2(0, -1)
|
||||
degrees = pi / 180
|
||||
|
||||
print "Using radians:"
|
||||
print " sin(-pi / 6) =", sin(-pi / 6)
|
||||
print " cos(3 * pi / 4) =", cos(3 * pi / 4)
|
||||
print " tan(pi / 3) =", tan(pi / 3)
|
||||
print " asin(-1 / 2) =", asin(-1 / 2)
|
||||
print " acos(-sqrt(2) / 2) =", acos(-sqrt(2) / 2)
|
||||
print " atan(sqrt(3)) =", atan(sqrt(3))
|
||||
|
||||
print "Using degrees:"
|
||||
print " sin(-30) =", sin(-30 * degrees)
|
||||
print " cos(135) =", cos(135 * degrees)
|
||||
print " tan(60) =", tan(60 * degrees)
|
||||
print " asin(-1 / 2) =", asin(-1 / 2) / degrees
|
||||
print " acos(-sqrt(2) / 2) =", acos(-sqrt(2) / 2) / degrees
|
||||
print " atan(sqrt(3)) =", atan(sqrt(3)) / degrees
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
trace("Radians:");
|
||||
trace("sin(Pi/4) = ", Math.sin(Math.PI/4));
|
||||
trace("cos(Pi/4) = ", Math.cos(Math.PI/4));
|
||||
trace("tan(Pi/4) = ", Math.tan(Math.PI/4));
|
||||
trace("arcsin(0.5) = ", Math.asin(0.5));
|
||||
trace("arccos(0.5) = ", Math.acos(0.5));
|
||||
trace("arctan(0.5) = ", Math.atan(0.5));
|
||||
trace("arctan2(-1,-2) = ", Math.atan2(-1,-2));
|
||||
trace("\nDegrees")
|
||||
trace("sin(45) = ", Math.sin(45 * Math.PI/180));
|
||||
trace("cos(45) = ", Math.cos(45 * Math.PI/180));
|
||||
trace("tan(45) = ", Math.tan(45 * Math.PI/180));
|
||||
trace("arcsin(0.5) = ", Math.asin(0.5)*180/Math.PI);
|
||||
trace("arccos(0.5) = ", Math.acos(0.5)*180/Math.PI);
|
||||
trace("arctan(0.5) = ", Math.atan(0.5)*180/Math.PI);
|
||||
trace("arctan2(-1,-2) = ", Math.atan2(-1,-2)*180/Math.PI);
|
||||
35
Task/Trigonometric-functions/Ada/trigonometric-functions.ada
Normal file
35
Task/Trigonometric-functions/Ada/trigonometric-functions.ada
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
with Ada.Numerics.Elementary_Functions;
|
||||
use Ada.Numerics.Elementary_Functions;
|
||||
with Ada.Float_Text_Io; use Ada.Float_Text_Io;
|
||||
with Ada.Text_IO; use Ada.Text_IO;
|
||||
|
||||
procedure Trig is
|
||||
Degrees_Cycle : constant Float := 360.0;
|
||||
Radians_Cycle : constant Float := 2.0 * Ada.Numerics.Pi;
|
||||
Angle_Degrees : constant Float := 45.0;
|
||||
Angle_Radians : constant Float := Ada.Numerics.Pi / 4.0;
|
||||
procedure Put (V1, V2 : Float) is
|
||||
begin
|
||||
Put (V1, Aft => 5, Exp => 0);
|
||||
Put (" ");
|
||||
Put (V2, Aft => 5, Exp => 0);
|
||||
New_Line;
|
||||
end Put;
|
||||
begin
|
||||
Put (Sin (Angle_Degrees, Degrees_Cycle),
|
||||
Sin (Angle_Radians, Radians_Cycle));
|
||||
Put (Cos (Angle_Degrees, Degrees_Cycle),
|
||||
Cos (Angle_Radians, Radians_Cycle));
|
||||
Put (Tan (Angle_Degrees, Degrees_Cycle),
|
||||
Tan (Angle_Radians, Radians_Cycle));
|
||||
Put (Cot (Angle_Degrees, Degrees_Cycle),
|
||||
Cot (Angle_Radians, Radians_Cycle));
|
||||
Put (ArcSin (Sin (Angle_Degrees, Degrees_Cycle), Degrees_Cycle),
|
||||
ArcSin (Sin (Angle_Radians, Radians_Cycle), Radians_Cycle));
|
||||
Put (Arccos (Cos (Angle_Degrees, Degrees_Cycle), Degrees_Cycle),
|
||||
Arccos (Cos (Angle_Radians, Radians_Cycle), Radians_Cycle));
|
||||
Put (Arctan (Y => Tan (Angle_Degrees, Degrees_Cycle)),
|
||||
Arctan (Y => Tan (Angle_Radians, Radians_Cycle)));
|
||||
Put (Arccot (X => Cot (Angle_Degrees, Degrees_Cycle)),
|
||||
Arccot (X => Cot (Angle_Degrees, Degrees_Cycle)));
|
||||
end Trig;
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
100 TAU = 8 * ATN (1)
|
||||
110 RAD = TAU / 8
|
||||
120 DEG = 45.0
|
||||
130 DEF FN RAD(DEG) = DEG * TAU / 360
|
||||
140 DEF FN DEG(RAD) = RAD / TAU * 360
|
||||
150 DEF FN ASN(RAD) = ATN (RAD / SQR ( - RAD * RAD + 1))
|
||||
160 DEF FN ACS(RAD) = - ATN (RAD / SQR ( - RAD * RAD + 1)) + TAU / 4
|
||||
170 PRINT " SINE: " SIN (RAD);: HTAB (25): PRINT SIN ( FN RAD(DEG))
|
||||
180 PRINT " COSINE: " COS (RAD);: HTAB (25): PRINT COS ( FN RAD(DEG))
|
||||
190 PRINT " TANGENT: " TAN (RAD);: HTAB (25): PRINT TAN ( FN RAD(DEG))
|
||||
200 ARC = FN ASN( SIN (RAD))
|
||||
210 PRINT " ARCSINE: "ARC;: HTAB (25): PRINT FN DEG(ARC)
|
||||
220 ARC = FN ACS( COS (RAD))
|
||||
230 PRINT " ARCCOSINE: "ARC;: HTAB (25): PRINT FN DEG(ARC)
|
||||
240 ARC = ATN ( TAN (RAD))
|
||||
250 PRINT " ARCTANGENT: "ARC;: HTAB (25): PRINT FN DEG(ARC);
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
pi: 4*atan 1.0
|
||||
|
||||
radians: pi/4
|
||||
degrees: 45.0
|
||||
|
||||
print "sine"
|
||||
print [sin radians, sin degrees*pi/180]
|
||||
|
||||
print "cosine"
|
||||
print [cos radians, cos degrees*pi/180]
|
||||
|
||||
print "tangent"
|
||||
print [tan radians, tan degrees*pi/180]
|
||||
|
||||
print "arcsine"
|
||||
print [asin sin radians, (asin sin radians)*180/pi]
|
||||
|
||||
print "arccosine"
|
||||
print [acos cos radians, (acos cos radians)*180/pi]
|
||||
|
||||
print "arctangent"
|
||||
print [atan tan radians, (atan tan radians)*180/pi]
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
real pi = 4 * atan(1);
|
||||
real radian = pi / 4.0;
|
||||
real angulo = 45.0 * pi / 180;
|
||||
|
||||
write("Radians : ", radian);
|
||||
write("Degrees : ", angulo / pi * 180);
|
||||
write();
|
||||
write("Sine : ", sin(radian), sin(angulo));
|
||||
write("Cosine : ", cos(radian), cos(angulo));
|
||||
write("Tangent : ", tan(radian), tan(angulo));
|
||||
write();
|
||||
real temp = asin(sin(radian));
|
||||
write("Arc Sine : ", temp, temp * 180 / pi);
|
||||
temp = acos(cos(radian));
|
||||
write("Arc Cosine : ", temp, temp * 180 / pi);
|
||||
temp = atan(tan(radian));
|
||||
write("Arc Tangent : ", temp, temp * 180 / pi);
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
pi := 4 * atan(1)
|
||||
radians := pi / 4
|
||||
degrees := 45.0
|
||||
result .= "`n" . sin(radians) . " " . sin(degrees * pi / 180)
|
||||
result .= "`n" . cos(radians) . " " . cos(degrees * pi / 180)
|
||||
result .= "`n" . tan(radians) . " " . tan(degrees * pi / 180)
|
||||
|
||||
temp := asin(sin(radians))
|
||||
result .= "`n" . temp . " " . temp * 180 / pi
|
||||
|
||||
temp := acos(cos(radians))
|
||||
result .= "`n" . temp . " " . temp * 180 / pi
|
||||
|
||||
temp := atan(tan(radians))
|
||||
result .= "`n" . temp . " " . temp * 180 / pi
|
||||
|
||||
msgbox % result
|
||||
/* output
|
||||
---------------------------
|
||||
trig.ahk
|
||||
---------------------------
|
||||
0.707107 0.707107
|
||||
0.707107 0.707107
|
||||
1.000000 1.000000
|
||||
0.785398 45.000000
|
||||
0.785398 45.000000
|
||||
0.785398 45.000000
|
||||
*/
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
(defun rad_to_deg (rad)(* 180.0 (/ rad PI)))
|
||||
(defun deg_to_rad (deg)(* PI (/ deg 180.0)))
|
||||
|
||||
(defun asin (x)
|
||||
(cond
|
||||
((and(> x -1.0)(< x 1.0)) (atan (/ x (sqrt (- 1.0 (* x x))))))
|
||||
((= x -1.0) (* -1.0 (/ pi 2)))
|
||||
((= x 1) (/ pi 2))
|
||||
)
|
||||
)
|
||||
|
||||
(defun acos (x)
|
||||
(cond
|
||||
((and(>= x -1.0)(<= x 1.0)) (-(* pi 0.5) (asin x)))
|
||||
)
|
||||
)
|
||||
|
||||
(list
|
||||
(list "cos PI/6" (cos (/ pi 6)) "cos 30 deg" (cos (deg_to_rad 30)))
|
||||
(list "sin PI/4" (sin (/ pi 4)) "sin 45 deg" (sin (deg_to_rad 45)))
|
||||
(list "tan PI/3" (tan (/ pi 3))"tan 60 deg" (tan (deg_to_rad 60)))
|
||||
(list "asin 1 rad" (asin 1.0) "asin 1 rad (deg)" (rad_to_deg (asin 1.0)))
|
||||
(list "acos 1/2 rad" (acos (/ 1 2.0)) "acos 1/2 rad (deg)" (rad_to_deg (acos (/ 1 2.0))))
|
||||
(list "atan pi/12" (atan (/ pi 12)) "atan 15 deg" (rad_to_deg(atan(deg_to_rad 15))))
|
||||
)
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
Disp sin(43)▶Dec,i
|
||||
Disp cos(43)▶Dec,i
|
||||
Disp tan⁻¹(10,10)▶Dec,i
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
pi = 3.141592653589793#
|
||||
radians = pi / 4 'a.k.a. 45 degrees
|
||||
degrees = 45 * pi / 180 'convert 45 degrees to radians once
|
||||
PRINT SIN(radians) + " " + SIN(degrees) 'sine
|
||||
PRINT COS(radians) + " " + COS(degrees) 'cosine
|
||||
PRINT TAN(radians) + " " + TAN (degrees) 'tangent
|
||||
'arcsin
|
||||
thesin = SIN(radians)
|
||||
arcsin = ATN(thesin / SQR(1 - thesin ^ 2))
|
||||
PRINT arcsin + " " + arcsin * 180 / pi
|
||||
'arccos
|
||||
thecos = COS(radians)
|
||||
arccos = 2 * ATN(SQR(1 - thecos ^ 2) / (1 + thecos))
|
||||
PRINT arccos + " " + arccos * 180 / pi
|
||||
PRINT ATN(TAN(radians)) + " " + ATN(TAN(radians)) * 180 / pi 'arctan
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
radian = pi / 4
|
||||
angulo = 45.0 * pi / 180
|
||||
|
||||
print "Radians : "; radians(angulo); " ";
|
||||
print "Degrees : "; degrees(radian)
|
||||
print
|
||||
print "Sine : "; sin(radian); " "; sin(angulo)
|
||||
print "Cosine : "; cos(radian); " "; cos(angulo)
|
||||
print "Tangent : "; tan(radian); " "; tan(angulo)
|
||||
print
|
||||
#temp = asin(sin(radians(angulo)))
|
||||
temp = asin(sin(radian))
|
||||
print "Arc Sine : "; temp; " "; degrees(temp)
|
||||
temp = acos(cos(radian))
|
||||
print "Arc Cosine : "; temp; " "; degrees(temp)
|
||||
temp = atan(tan(radian))
|
||||
print "Arc Tangent : "; temp; " "; degrees(temp)
|
||||
end
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
@% = &90F : REM set column width
|
||||
|
||||
angle_radians = PI/5
|
||||
angle_degrees = 36
|
||||
|
||||
PRINT SIN(angle_radians), SIN(RAD(angle_degrees))
|
||||
PRINT COS(angle_radians), COS(RAD(angle_degrees))
|
||||
PRINT TAN(angle_radians), TAN(RAD(angle_degrees))
|
||||
|
||||
number = 0.6
|
||||
|
||||
PRINT ASN(number), DEG(ASN(number))
|
||||
PRINT ACS(number), DEG(ACS(number))
|
||||
PRINT ATN(number), DEG(ATN(number))
|
||||
25
Task/Trigonometric-functions/BQN/trigonometric-functions.bqn
Normal file
25
Task/Trigonometric-functions/BQN/trigonometric-functions.bqn
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
⟨sin, cos, tan⟩ ← •math
|
||||
Sin 0
|
||||
0
|
||||
Sin π÷2
|
||||
1
|
||||
Cos 0
|
||||
1
|
||||
Cos π÷2
|
||||
6.123233995736766e¯17
|
||||
Tan 0
|
||||
0
|
||||
Tan π÷2
|
||||
16331239353195370
|
||||
Sin⁼ 0
|
||||
0
|
||||
Sin⁼ 1
|
||||
1.5707963267948966
|
||||
Cos⁼ 1
|
||||
0
|
||||
Cos⁼ 0
|
||||
1.5707963267948966
|
||||
Tan⁼ 0
|
||||
0
|
||||
Tan⁼ ∞
|
||||
1.5707963267948966
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
' Trigonometric functions in BaCon use Radians for input values
|
||||
' The RAD() function converts from degrees to radians
|
||||
|
||||
FOR v$ IN "0, 10, 45, 90, 190.5"
|
||||
d = VAL(v$) * 1.0
|
||||
r = RAD(d) * 1.0
|
||||
|
||||
PRINT "Sine: ", d, " degrees (or ", r, " radians) is ", SIN(r)
|
||||
PRINT "Cosine: ", d, " degrees (or ", r, " radians) is ", COS(r)
|
||||
PRINT "Tangent: ", d, " degrees (or ", r, " radians) is ", TAN(r)
|
||||
PRINT
|
||||
PRINT "Arc Sine: ", SIN(r), " is ", DEG(ASIN(SIN(r))), " degrees (or ", ASIN(SIN(r)), " radians)"
|
||||
PRINT "Arc CoSine: ", COS(r), " is ", DEG(ACOS(COS(r))), " degrees (or ", ACOS(COS(r)), " radians)"
|
||||
PRINT "Arc Tangent: ", TAN(r), " is ", DEG(ATN(TAN(r))), " degrees (or ", ATN(TAN(r)), " radians)"
|
||||
PRINT
|
||||
NEXT
|
||||
55
Task/Trigonometric-functions/Bc/trigonometric-functions.bc
Normal file
55
Task/Trigonometric-functions/Bc/trigonometric-functions.bc
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
/* t(x) = tangent of x */
|
||||
define t(x) {
|
||||
return s(x) / c(x)
|
||||
}
|
||||
|
||||
/* y(y) = arcsine of y, domain [-1, 1], range [-pi/2, pi/2] */
|
||||
define y(y) {
|
||||
/* Handle angles with no tangent. */
|
||||
if (y == -1) return -2 * a(1) /* -pi/2 */
|
||||
if (y == 1) return 2 * a(1) /* pi/2 */
|
||||
|
||||
/* Tangent of angle is y / x, where x^2 + y^2 = 1. */
|
||||
return a(y / sqrt(1 - y * y))
|
||||
}
|
||||
|
||||
/* x(x) = arccosine of x, domain [-1, 1], range [0, pi] */
|
||||
define x(x) {
|
||||
auto a
|
||||
|
||||
/* Handle angle with no tangent. */
|
||||
if (x == 0) return 2 * a(1) /* pi/2 */
|
||||
|
||||
/* Tangent of angle is y / x, where x^2 + y^2 = 1. */
|
||||
a = a(sqrt(1 - x * x) / x)
|
||||
if (a < 0) {
|
||||
return a + 4 * a(1) /* add pi */
|
||||
} else {
|
||||
return a
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
scale = 50
|
||||
p = 4 * a(1) /* pi */
|
||||
d = p / 180 /* one degree in radians */
|
||||
|
||||
"Using radians:
|
||||
"
|
||||
" sin(-pi / 6) = "; s(-p / 6)
|
||||
" cos(3 * pi / 4) = "; c(3 * p / 4)
|
||||
" tan(pi / 3) = "; t(p / 3)
|
||||
" asin(-1 / 2) = "; y(-1 / 2)
|
||||
" acos(-sqrt(2) / 2) = "; x(-sqrt(2) / 2)
|
||||
" atan(sqrt(3)) = "; a(sqrt(3))
|
||||
|
||||
"Using degrees:
|
||||
"
|
||||
" sin(-30) = "; s(-30 * d)
|
||||
" cos(135) = "; c(135 * d)
|
||||
" tan(60) = "; t(60 * d)
|
||||
" asin(-1 / 2) = "; y(-1 / 2) / d
|
||||
" acos(-sqrt(2) / 2) = "; x(-sqrt(2) / 2) / d
|
||||
" atan(sqrt(3)) = "; a(sqrt(3)) / d
|
||||
|
||||
quit
|
||||
31
Task/Trigonometric-functions/C++/trigonometric-functions.cpp
Normal file
31
Task/Trigonometric-functions/C++/trigonometric-functions.cpp
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
#include <iostream>
|
||||
#include <cmath>
|
||||
|
||||
#ifdef M_PI // defined by all POSIX systems and some non-POSIX ones
|
||||
double const pi = M_PI;
|
||||
#else
|
||||
double const pi = 4*std::atan(1);
|
||||
#endif
|
||||
|
||||
double const degree = pi/180;
|
||||
|
||||
int main()
|
||||
{
|
||||
std::cout << "=== radians ===\n";
|
||||
std::cout << "sin(pi/3) = " << std::sin(pi/3) << "\n";
|
||||
std::cout << "cos(pi/3) = " << std::cos(pi/3) << "\n";
|
||||
std::cout << "tan(pi/3) = " << std::tan(pi/3) << "\n";
|
||||
std::cout << "arcsin(1/2) = " << std::asin(0.5) << "\n";
|
||||
std::cout << "arccos(1/2) = " << std::acos(0.5) << "\n";
|
||||
std::cout << "arctan(1/2) = " << std::atan(0.5) << "\n";
|
||||
|
||||
std::cout << "\n=== degrees ===\n";
|
||||
std::cout << "sin(60°) = " << std::sin(60*degree) << "\n";
|
||||
std::cout << "cos(60°) = " << std::cos(60*degree) << "\n";
|
||||
std::cout << "tan(60°) = " << std::tan(60*degree) << "\n";
|
||||
std::cout << "arcsin(1/2) = " << std::asin(0.5)/degree << "°\n";
|
||||
std::cout << "arccos(1/2) = " << std::acos(0.5)/degree << "°\n";
|
||||
std::cout << "arctan(1/2) = " << std::atan(0.5)/degree << "°\n";
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
using System;
|
||||
|
||||
namespace RosettaCode {
|
||||
class Program {
|
||||
static void Main(string[] args) {
|
||||
Console.WriteLine("=== radians ===");
|
||||
Console.WriteLine("sin (pi/3) = {0}", Math.Sin(Math.PI / 3));
|
||||
Console.WriteLine("cos (pi/3) = {0}", Math.Cos(Math.PI / 3));
|
||||
Console.WriteLine("tan (pi/3) = {0}", Math.Tan(Math.PI / 3));
|
||||
Console.WriteLine("arcsin (1/2) = {0}", Math.Asin(0.5));
|
||||
Console.WriteLine("arccos (1/2) = {0}", Math.Acos(0.5));
|
||||
Console.WriteLine("arctan (1/2) = {0}", Math.Atan(0.5));
|
||||
Console.WriteLine("");
|
||||
Console.WriteLine("=== degrees ===");
|
||||
Console.WriteLine("sin (60) = {0}", Math.Sin(60 * Math.PI / 180));
|
||||
Console.WriteLine("cos (60) = {0}", Math.Cos(60 * Math.PI / 180));
|
||||
Console.WriteLine("tan (60) = {0}", Math.Tan(60 * Math.PI / 180));
|
||||
Console.WriteLine("arcsin (1/2) = {0}", Math.Asin(0.5) * 180/ Math.PI);
|
||||
Console.WriteLine("arccos (1/2) = {0}", Math.Acos(0.5) * 180 / Math.PI);
|
||||
Console.WriteLine("arctan (1/2) = {0}", Math.Atan(0.5) * 180 / Math.PI);
|
||||
|
||||
Console.ReadLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
27
Task/Trigonometric-functions/C/trigonometric-functions.c
Normal file
27
Task/Trigonometric-functions/C/trigonometric-functions.c
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
double pi = 4 * atan(1);
|
||||
/*Pi / 4 is 45 degrees. All answers should be the same.*/
|
||||
double radians = pi / 4;
|
||||
double degrees = 45.0;
|
||||
double temp;
|
||||
/*sine*/
|
||||
printf("%f %f\n", sin(radians), sin(degrees * pi / 180));
|
||||
/*cosine*/
|
||||
printf("%f %f\n", cos(radians), cos(degrees * pi / 180));
|
||||
/*tangent*/
|
||||
printf("%f %f\n", tan(radians), tan(degrees * pi / 180));
|
||||
/*arcsine*/
|
||||
temp = asin(sin(radians));
|
||||
printf("%f %f\n", temp, temp * 180 / pi);
|
||||
/*arccosine*/
|
||||
temp = acos(cos(radians));
|
||||
printf("%f %f\n", temp, temp * 180 / pi);
|
||||
/*arctangent*/
|
||||
temp = atan(tan(radians));
|
||||
printf("%f %f\n", temp, temp * 180 / pi);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -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
|
||||
.
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
(ns user
|
||||
(:require [clojure.contrib.generic.math-functions :as generic]))
|
||||
|
||||
;(def pi Math/PI)
|
||||
(def pi (* 4 (atan 1)))
|
||||
(def dtor (/ pi 180))
|
||||
(def rtod (/ 180 pi))
|
||||
(def radians (/ pi 4))
|
||||
(def degrees 45)
|
||||
|
||||
(println (str (sin radians) " " (sin (* degrees dtor))))
|
||||
(println (str (cos radians) " " (cos (* degrees dtor))))
|
||||
(println (str (tan radians) " " (tan (* degrees dtor))))
|
||||
(println (str (asin (sin radians) ) " " (* (asin (sin (* degrees dtor))) rtod)))
|
||||
(println (str (acos (cos radians) ) " " (* (acos (cos (* degrees dtor))) rtod)))
|
||||
(println (str (atan (tan radians) ) " " (* (atan (tan (* degrees dtor))) rtod)))
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
(defun deg->rad (x) (* x (/ pi 180)))
|
||||
(defun rad->deg (x) (* x (/ 180 pi)))
|
||||
|
||||
(mapc (lambda (x) (format t "~s => ~s~%" x (eval x)))
|
||||
'((sin (/ pi 4))
|
||||
(sin (deg->rad 45))
|
||||
(cos (/ pi 6))
|
||||
(cos (deg->rad 30))
|
||||
(tan (/ pi 3))
|
||||
(tan (deg->rad 60))
|
||||
(asin 1)
|
||||
(rad->deg (asin 1))
|
||||
(acos 1/2)
|
||||
(rad->deg (acos 1/2))
|
||||
(atan 15)
|
||||
(rad->deg (atan 15))))
|
||||
21
Task/Trigonometric-functions/D/trigonometric-functions.d
Normal file
21
Task/Trigonometric-functions/D/trigonometric-functions.d
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
void main() {
|
||||
import std.stdio, std.math;
|
||||
|
||||
enum degrees = 45.0L;
|
||||
enum t0 = degrees * PI / 180.0L;
|
||||
writeln("Reference: 0.7071067811865475244008");
|
||||
writefln("Sine: %.20f %.20f", PI_4.sin, t0.sin);
|
||||
writefln("Cosine: %.20f %.20f", PI_4.cos, t0.cos);
|
||||
writefln("Tangent: %.20f %.20f", PI_4.tan, t0.tan);
|
||||
|
||||
writeln;
|
||||
writeln("Reference: 0.7853981633974483096156");
|
||||
immutable real t1 = PI_4.sin.asin;
|
||||
writefln("Arcsine: %.20f %.20f", t1, t1 * 180.0L / PI);
|
||||
|
||||
immutable real t2 = PI_4.cos.acos;
|
||||
writefln("Arccosine: %.20f %.20f", t2, t2 * 180.0L / PI);
|
||||
|
||||
immutable real t3 = PI_4.tan.atan;
|
||||
writefln("Arctangent: %.20f %.20f", t3, t3 * 180.0L / PI);
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
procedure ShowTrigFunctions(Memo: TMemo);
|
||||
const AngleDeg = 45.0;
|
||||
var AngleRad,ArcSine,ArcCosine,ArcTangent: double;
|
||||
begin
|
||||
AngleRad:=DegToRad(AngleDeg);
|
||||
|
||||
Memo.Lines.Add(Format('Angle: Degrees: %3.5f Radians: %3.6f',[AngleDeg,AngleRad]));
|
||||
Memo.Lines.Add('-------------------------------------------------');
|
||||
Memo.Lines.Add(Format('Sine: Degrees: %3.6f Radians: %3.6f',[sin(DegToRad(AngleDeg)),sin(AngleRad)]));
|
||||
Memo.Lines.Add(Format('Cosine: Degrees: %3.6f Radians: %3.6f',[cos(DegToRad(AngleDeg)),cos(AngleRad)]));
|
||||
Memo.Lines.Add(Format('Tangent: Degrees: %3.6f Radians: %3.6f',[tan(DegToRad(AngleDeg)),tan(AngleRad)]));
|
||||
ArcSine:=ArcSin(Sin(AngleRad));
|
||||
Memo.Lines.Add(Format('Arcsine: Degrees: %3.6f Radians: %3.6f',[DegToRad(ArcSine),ArcSine]));
|
||||
ArcCosine:=ArcCos(cos(AngleRad));
|
||||
Memo.Lines.Add(Format('Arccosine: Degrees: %3.6f Radians: %3.6f',[DegToRad(ArcCosine),ArcCosine]));
|
||||
ArcTangent:=ArcTan(tan(AngleRad));
|
||||
Memo.Lines.Add(Format('Arctangent: Degrees: %3.6f Radians: %3.6f',[DegToRad(ArcTangent),ArcTangent]));
|
||||
end;
|
||||
16
Task/Trigonometric-functions/E/trigonometric-functions.e
Normal file
16
Task/Trigonometric-functions/E/trigonometric-functions.e
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
def pi := (-1.0).acos()
|
||||
|
||||
def radians := pi / 4.0
|
||||
def degrees := 45.0
|
||||
|
||||
def d2r := (pi/180).multiply
|
||||
def r2d := (180/pi).multiply
|
||||
|
||||
println(`$\
|
||||
${radians.sin()} ${d2r(degrees).sin()}
|
||||
${radians.cos()} ${d2r(degrees).cos()}
|
||||
${radians.tan()} ${d2r(degrees).tan()}
|
||||
${def asin := radians.sin().asin()} ${r2d(asin)}
|
||||
${def acos := radians.cos().acos()} ${r2d(acos)}
|
||||
${def atan := radians.tan().atan()} ${r2d(atan)}
|
||||
`)
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
import system'math;
|
||||
import extensions;
|
||||
|
||||
public program()
|
||||
{
|
||||
console.printLine("Radians:");
|
||||
console.printLine("sin(π/3) = ",(Pi_value/3).sin());
|
||||
console.printLine("cos(π/3) = ",(Pi_value/3).cos());
|
||||
console.printLine("tan(π/3) = ",(Pi_value/3).tan());
|
||||
console.printLine("arcsin(1/2) = ",0.5r.arcsin());
|
||||
console.printLine("arccos(1/2) = ",0.5r.arccos());
|
||||
console.printLine("arctan(1/2) = ",0.5r.arctan());
|
||||
console.printLine();
|
||||
|
||||
console.printLine("Degrees:");
|
||||
console.printLine("sin(60º) = ",60.0r.Radian.sin());
|
||||
console.printLine("cos(60º) = ",60.0r.Radian.cos());
|
||||
console.printLine("tan(60º) = ",60.0r.Radian.tan());
|
||||
console.printLine("arcsin(1/2) = ",0.5r.arcsin().Degree,"º");
|
||||
console.printLine("arccos(1/2) = ",0.5r.arccos().Degree,"º");
|
||||
console.printLine("arctan(1/2) = ",0.5r.arctan().Degree,"º");
|
||||
|
||||
console.readChar()
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
iex(61)> deg = 45
|
||||
45
|
||||
iex(62)> rad = :math.pi / 4
|
||||
0.7853981633974483
|
||||
iex(63)> :math.sin(deg * :math.pi / 180) == :math.sin(rad)
|
||||
true
|
||||
iex(64)> :math.cos(deg * :math.pi / 180) == :math.cos(rad)
|
||||
true
|
||||
iex(65)> :math.tan(deg * :math.pi / 180) == :math.tan(rad)
|
||||
true
|
||||
iex(66)> temp = :math.acos(:math.cos(rad))
|
||||
0.7853981633974483
|
||||
iex(67)> temp * 180 / :math.pi == deg
|
||||
true
|
||||
iex(68)> temp = :math.atan(:math.tan(rad))
|
||||
0.7853981633974483
|
||||
iex(69)> temp * 180 / :math.pi == deg
|
||||
true
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
Deg=45.
|
||||
Rad=math:pi()/4.
|
||||
|
||||
math:sin(Deg * math:pi() / 180)==math:sin(Rad).
|
||||
|
|
@ -0,0 +1 @@
|
|||
math:cos(Deg * math:pi() / 180)==math:cos(Rad).
|
||||
|
|
@ -0,0 +1 @@
|
|||
math:tan(Deg * math:pi() / 180)==math:tan(Rad).
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
Temp = math:acos(math:cos(Rad)).
|
||||
Temp * 180 / math:pi()==Deg.
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
Temp = math:atan(math:tan(Rad)).
|
||||
Temp * 180 / math:pi()==Deg.
|
||||
122
Task/Trigonometric-functions/F-Sharp/trigonometric-functions.fs
Normal file
122
Task/Trigonometric-functions/F-Sharp/trigonometric-functions.fs
Normal file
|
|
@ -0,0 +1,122 @@
|
|||
open NUnit.Framework
|
||||
open FsUnit
|
||||
|
||||
// radian
|
||||
|
||||
[<Test>]
|
||||
let ``Verify that sin pi returns 0`` () =
|
||||
let x = System.Math.Sin System.Math.PI
|
||||
System.Math.Round(x,5) |> should equal 0
|
||||
|
||||
[<Test>]
|
||||
let ``Verify that cos pi returns -1`` () =
|
||||
let x = System.Math.Cos System.Math.PI
|
||||
System.Math.Round(x,5) |> should equal -1
|
||||
|
||||
[<Test>]
|
||||
let ``Verify that tan pi returns 0`` () =
|
||||
let x = System.Math.Tan System.Math.PI
|
||||
System.Math.Round(x,5) |> should equal 0
|
||||
|
||||
[<Test>]
|
||||
let ``Verify that sin pi/2 returns 1`` () =
|
||||
let x = System.Math.Sin (System.Math.PI / 2.0)
|
||||
System.Math.Round(x,5) |> should equal 1
|
||||
|
||||
[<Test>]
|
||||
let ``Verify that cos pi/2 returns -1`` () =
|
||||
let x = System.Math.Cos (System.Math.PI / 2.0)
|
||||
System.Math.Round(x,5) |> should equal 0
|
||||
|
||||
[<Test>]
|
||||
let ``Verify that sin pi/3 returns sqrt 3/2`` () =
|
||||
let actual = System.Math.Sin (System.Math.PI / 3.0)
|
||||
let expected = System.Math.Round((System.Math.Sqrt 3.0) / 2.0, 5)
|
||||
System.Math.Round(actual,5) |> should equal expected
|
||||
|
||||
[<Test>]
|
||||
let ``Verify that cos pi/3 returns -1`` () =
|
||||
let x = System.Math.Cos (System.Math.PI / 3.0)
|
||||
System.Math.Round(x,5) |> should equal 0.5
|
||||
|
||||
[<Test>]
|
||||
let ``Verify that cos and sin of pi/4 return same value`` () =
|
||||
let c = System.Math.Cos (System.Math.PI / 4.0)
|
||||
let s = System.Math.Sin (System.Math.PI / 4.0)
|
||||
System.Math.Round(c,5) = System.Math.Round(s,5) |> should be True
|
||||
|
||||
[<Test>]
|
||||
let ``Verify that acos pi/3 returns 1/2`` () =
|
||||
let actual = System.Math.Acos 0.5
|
||||
let expected = System.Math.Round((System.Math.PI / 3.0),5)
|
||||
System.Math.Round(actual,5) |> should equal expected
|
||||
|
||||
[<Test>]
|
||||
let ``Verify that asin 1 returns pi/2`` () =
|
||||
let actual = System.Math.Asin 1.0
|
||||
let expected = System.Math.Round((System.Math.PI / 2.0),5)
|
||||
System.Math.Round(actual,5) |> should equal expected
|
||||
|
||||
[<Test>]
|
||||
let ``Verify that atan 0 returns 0`` () =
|
||||
let actual = System.Math.Atan 0.0
|
||||
let expected = System.Math.Round(0.0,5)
|
||||
System.Math.Round(actual,5) |> should equal expected
|
||||
|
||||
// degree
|
||||
|
||||
let toRadians d = d * System.Math.PI / 180.0
|
||||
|
||||
[<Test>]
|
||||
let ``Verify that pi is 180 degrees`` () =
|
||||
toRadians 180.0 |> should equal System.Math.PI
|
||||
|
||||
[<Test>]
|
||||
let ``Verify that pi/2 is 90 degrees`` () =
|
||||
toRadians 90.0 |> should equal (System.Math.PI / 2.0)
|
||||
|
||||
[<Test>]
|
||||
let ``Verify that pi/3 is 60 degrees`` () =
|
||||
toRadians 60.0 |> should equal (System.Math.PI / 3.0)
|
||||
|
||||
[<Test>]
|
||||
let ``Verify that sin 180 returns 0`` () =
|
||||
let x = System.Math.Sin (toRadians 180.0)
|
||||
System.Math.Round(x,5) |> should equal 0
|
||||
|
||||
[<Test>]
|
||||
let ``Verify that cos 180 returns -1`` () =
|
||||
let x = System.Math.Cos (toRadians 180.0)
|
||||
System.Math.Round(x,5) |> should equal -1
|
||||
|
||||
[<Test>]
|
||||
let ``Verify that tan 180 returns 0`` () =
|
||||
let x = System.Math.Tan (toRadians 180.0)
|
||||
System.Math.Round(x,5) |> should equal 0
|
||||
|
||||
[<Test>]
|
||||
let ``Verify that sin 90 returns 1`` () =
|
||||
let x = System.Math.Sin (toRadians 90.0)
|
||||
System.Math.Round(x,5) |> should equal 1
|
||||
|
||||
[<Test>]
|
||||
let ``Verify that cos 90 returns -1`` () =
|
||||
let x = System.Math.Cos (toRadians 90.0)
|
||||
System.Math.Round(x,5) |> should equal 0
|
||||
|
||||
[<Test>]
|
||||
let ``Verify that sin 60 returns sqrt 3/2`` () =
|
||||
let actual = System.Math.Sin (toRadians 60.0)
|
||||
let expected = System.Math.Round((System.Math.Sqrt 3.0) / 2.0, 5)
|
||||
System.Math.Round(actual,5) |> should equal expected
|
||||
|
||||
[<Test>]
|
||||
let ``Verify that cos 60 returns -1`` () =
|
||||
let x = System.Math.Cos (toRadians 60.0)
|
||||
System.Math.Round(x,5) |> should equal 0.5
|
||||
|
||||
[<Test>]
|
||||
let ``Verify that cos and sin of 45 return same value`` () =
|
||||
let c = System.Math.Cos (toRadians 45.0)
|
||||
let s = System.Math.Sin (toRadians 45.0)
|
||||
System.Math.Round(c,5) = System.Math.Round(s,5) |> should be True
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
USING: kernel math math.constants math.functions math.trig
|
||||
prettyprint ;
|
||||
|
||||
pi 4 / 45 deg>rad [ sin ] [ cos ] [ tan ]
|
||||
[ [ . ] compose dup compose ] tri@ 2tri
|
||||
|
||||
.5 [ asin ] [ acos ] [ atan ] tri [ dup rad>deg [ . ] bi@ ] tri@
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
class Main
|
||||
{
|
||||
public static Void main ()
|
||||
{
|
||||
Float r := Float.pi / 4
|
||||
echo (r.sin)
|
||||
echo (r.cos)
|
||||
echo (r.tan)
|
||||
echo (r.asin)
|
||||
echo (r.acos)
|
||||
echo (r.atan)
|
||||
// and from degrees
|
||||
echo (45.0f.toRadians.sin)
|
||||
echo (45.0f.toRadians.cos)
|
||||
echo (45.0f.toRadians.tan)
|
||||
echo (45.0f.toRadians.asin)
|
||||
echo (45.0f.toRadians.acos)
|
||||
echo (45.0f.toRadians.atan)
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
45e pi f* 180e f/ \ radians
|
||||
|
||||
cr fdup fsin f. \ also available: fsincos ( r -- sin cos )
|
||||
cr fdup fcos f.
|
||||
cr fdup ftan f.
|
||||
cr fdup fasin f.
|
||||
cr fdup facos f.
|
||||
cr fatan f. \ also available: fatan2 ( r1 r2 -- atan[r1/r2] )
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
PROGRAM Trig
|
||||
|
||||
REAL pi, dtor, rtod, radians, degrees
|
||||
|
||||
pi = 4.0 * ATAN(1.0)
|
||||
dtor = pi / 180.0
|
||||
rtod = 180.0 / pi
|
||||
radians = pi / 4.0
|
||||
degrees = 45.0
|
||||
|
||||
WRITE(*,*) SIN(radians), SIN(degrees*dtor)
|
||||
WRITE(*,*) COS(radians), COS(degrees*dtor)
|
||||
WRITE(*,*) TAN(radians), TAN(degrees*dtor)
|
||||
WRITE(*,*) ASIN(SIN(radians)), ASIN(SIN(degrees*dtor))*rtod
|
||||
WRITE(*,*) ACOS(COS(radians)), ACOS(COS(degrees*dtor))*rtod
|
||||
WRITE(*,*) ATAN(TAN(radians)), ATAN(TAN(degrees*dtor))*rtod
|
||||
|
||||
END PROGRAM Trig
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
ATAN2(y,x) ! Arctangent(y/x), ''-pi < result <= +pi''
|
||||
SINH(x) ! Hyperbolic sine
|
||||
COSH(x) ! Hyperbolic cosine
|
||||
TANH(x) ! Hyperbolic tangent
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
Calculate various trigonometric functions from the Fortran library.
|
||||
INTEGER BIT(32),B,IP !Stuff for bit fiddling.
|
||||
INTEGER ENUFF,I !Step through the test angles.
|
||||
PARAMETER (ENUFF = 17) !A selection of special values.
|
||||
INTEGER ANGLE(ENUFF) !All in whole degrees.
|
||||
DATA ANGLE/0,30,45,60,90,120,135,150,180, !Here they are.
|
||||
1 210,225,240,270,300,315,330,360/ !Thus check angle folding.
|
||||
REAL PI,DEG2RAD !Special numbers.
|
||||
REAL D,R,FD,FR,AD,AR !Degree, Radian, F(D), F(R), inverses.
|
||||
PI = 4*ATAN(1.0) !SINGLE PRECISION 1·0.
|
||||
DEG2RAD = PI/180 !Limited precision here too for a transcendental number.
|
||||
Case the first: sines.
|
||||
WRITE (6,10) ("Sin", I = 1,4) !Supply some names.
|
||||
10 FORMAT (" Deg.",A7,"(Deg)",A7,"(Rad) Rad - Deg", !Ah, layout.
|
||||
1 6X,"Arc",A3,"D",6X,"Arc",A3,"R",9X,"Diff")
|
||||
DO I = 1,ENUFF !Step through the test values.
|
||||
D = ANGLE(I) !The angle in degrees, in floating point.
|
||||
R = D*DEG2RAD !Approximation, in radians.
|
||||
FD = SIND(D); AD = ASIND(FD) !Functions working in degrees.
|
||||
FR = SIN(R); AR = ASIN(FR)/DEG2RAD !Functions working in radians.
|
||||
WRITE (6,11) INT(D),FD,FR,FR - FD,AD,AR,AR - AD !Results.
|
||||
11 FORMAT (I4,":",3F12.8,3F13.7) !Ah, alignment with FORMAT 10...
|
||||
END DO !On to the next test value.
|
||||
Case the second: cosines.
|
||||
WRITE (6,10) ("Cos", I = 1,4)
|
||||
DO I = 1,ENUFF
|
||||
D = ANGLE(I)
|
||||
R = D*DEG2RAD
|
||||
FD = COSD(D); AD = ACOSD(FD)
|
||||
FR = COS(R); AR = ACOS(FR)/DEG2RAD
|
||||
WRITE (6,11) INT(D),FD,FR,FR - FD,AD,AR,AR - AD
|
||||
END DO
|
||||
Case the third: tangents.
|
||||
WRITE (6,10) ("Tan", I = 1,4)
|
||||
DO I = 1,ENUFF
|
||||
D = ANGLE(I)
|
||||
R = D*DEG2RAD
|
||||
FD = TAND(D); AD = ATAND(FD)
|
||||
FR = TAN(R); AR = ATAN(FR)/DEG2RAD
|
||||
WRITE (6,11) INT(D),FD,FR,FR - FD,AD,AR,AR - AD
|
||||
END DO
|
||||
WRITE (6,*) "...Special deal for 90 degrees..."
|
||||
D = 90
|
||||
R = D*DEG2RAD
|
||||
FD = TAND(D); AD = ATAND(FD)
|
||||
FR = TAN(R); AR = ATAN(FR)/DEG2RAD
|
||||
WRITE (6,*) "TanD =",FD,"Atan =",AD
|
||||
WRITE (6,*) "TanR =",FR,"Atan =",AR
|
||||
Convert PI to binary...
|
||||
PI = PI - 3 !I know it starts with three, and I need the fractional part.
|
||||
BIT(1:2) = 1 !So, the binary is 11. something.
|
||||
B = 2 !Two bits known.
|
||||
DO I = 1,26 !For single precision, more than enough additional bits.
|
||||
PI = PI*2 !Hoist a bit to the hot spot.
|
||||
IP = PI !The integral part.
|
||||
PI = PI - IP !Remove it from the work in progress.
|
||||
B = B + 1 !Another bit bitten.
|
||||
BIT(B) = IP !Place it.
|
||||
END DO !On to the next.
|
||||
WRITE (6,20) BIT(1:B) !Reveal the bits.
|
||||
20 FORMAT (" Pi ~ ",2I1,".",66I1) !A known format.
|
||||
WRITE (6,*) " = 11.00100100001111110110101010001000100001..." !But actually...
|
||||
END !So much for that.
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
' FB 1.05.0 Win64
|
||||
|
||||
Const pi As Double = 4 * Atn(1)
|
||||
Dim As Double radians = pi / 4
|
||||
Dim As Double degrees = 45.0 '' equivalent in degrees
|
||||
Dim As Double temp
|
||||
|
||||
Print "Radians : "; radians, " ";
|
||||
Print "Degrees : "; degrees
|
||||
Print
|
||||
Print "Sine : "; Sin(radians), Sin(degrees * pi / 180)
|
||||
Print "Cosine : "; Cos(radians), Cos(degrees * pi / 180)
|
||||
Print "Tangent : "; Tan(radians), Tan(degrees * pi / 180)
|
||||
Print
|
||||
temp = ASin(Sin(radians))
|
||||
Print "Arc Sine : "; temp, temp * 180 / pi
|
||||
temp = ACos(Cos(radians))
|
||||
Print "Arc Cosine : "; temp, temp * 180 / pi
|
||||
temp = Atn(Tan(radians))
|
||||
Print "Arc Tangent : "; temp, temp * 180 / pi
|
||||
Sleep
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
include "NSLog.incl"
|
||||
|
||||
void local fn DoIt
|
||||
double degrees = 45.0
|
||||
double radians = degrees * M_PI / 180
|
||||
|
||||
NSLog(@"%f, %f",sin(radians),sin(degrees * M_PI / 180))
|
||||
NSLog(@"%f, %f",cos(radians),cos(degrees * M_PI / 180))
|
||||
NSLog(@"%f, %f",tan(radians),tan(degrees * M_PI / 180))
|
||||
|
||||
NSLog(@"%f, %f",asin(sin(radians)),asin(sin(radians)) * 180 / M_PI)
|
||||
NSLog(@"%f, %f",acos(cos(radians)),acos(cos(radians)) * 180 / M_PI)
|
||||
NSLog(@"%f, %f",atan(tan(radians)),atan(tan(radians)) * 180 / M_PI)
|
||||
end fn
|
||||
|
||||
fn DoIt
|
||||
|
||||
HandleEvents
|
||||
18
Task/Trigonometric-functions/GAP/trigonometric-functions.gap
Normal file
18
Task/Trigonometric-functions/GAP/trigonometric-functions.gap
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
# GAP has an improved floating-point support since version 4.5
|
||||
|
||||
Pi := Acos(-1.0);
|
||||
|
||||
# Or use the built-in constant:
|
||||
Pi := FLOAT.PI;
|
||||
|
||||
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);
|
||||
28
Task/Trigonometric-functions/Go/trigonometric-functions.go
Normal file
28
Task/Trigonometric-functions/Go/trigonometric-functions.go
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
)
|
||||
|
||||
const d = 30.
|
||||
const r = d * math.Pi / 180
|
||||
|
||||
var s = .5
|
||||
var c = math.Sqrt(3) / 2
|
||||
var t = 1 / math.Sqrt(3)
|
||||
|
||||
func main() {
|
||||
fmt.Printf("sin(%9.6f deg) = %f\n", d, math.Sin(d*math.Pi/180))
|
||||
fmt.Printf("sin(%9.6f rad) = %f\n", r, math.Sin(r))
|
||||
fmt.Printf("cos(%9.6f deg) = %f\n", d, math.Cos(d*math.Pi/180))
|
||||
fmt.Printf("cos(%9.6f rad) = %f\n", r, math.Cos(r))
|
||||
fmt.Printf("tan(%9.6f deg) = %f\n", d, math.Tan(d*math.Pi/180))
|
||||
fmt.Printf("tan(%9.6f rad) = %f\n", r, math.Tan(r))
|
||||
fmt.Printf("asin(%f) = %9.6f deg\n", s, math.Asin(s)*180/math.Pi)
|
||||
fmt.Printf("asin(%f) = %9.6f rad\n", s, math.Asin(s))
|
||||
fmt.Printf("acos(%f) = %9.6f deg\n", c, math.Acos(c)*180/math.Pi)
|
||||
fmt.Printf("acos(%f) = %9.6f rad\n", c, math.Acos(c))
|
||||
fmt.Printf("atan(%f) = %9.6f deg\n", t, math.Atan(t)*180/math.Pi)
|
||||
fmt.Printf("atan(%f) = %9.6f rad\n", t, math.Atan(t))
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
def radians = Math.PI/4
|
||||
def degrees = 45
|
||||
|
||||
def d2r = { it*Math.PI/180 }
|
||||
def r2d = { it*180/Math.PI }
|
||||
|
||||
println "sin(\u03C0/4) = ${Math.sin(radians)} == sin(45\u00B0) = ${Math.sin(d2r(degrees))}"
|
||||
println "cos(\u03C0/4) = ${Math.cos(radians)} == cos(45\u00B0) = ${Math.cos(d2r(degrees))}"
|
||||
println "tan(\u03C0/4) = ${Math.tan(radians)} == tan(45\u00B0) = ${Math.tan(d2r(degrees))}"
|
||||
println "asin(\u221A2/2) = ${Math.asin(2**(-0.5))} == asin(\u221A2/2)\u00B0 = ${r2d(Math.asin(2**(-0.5)))}\u00B0"
|
||||
println "acos(\u221A2/2) = ${Math.acos(2**(-0.5))} == acos(\u221A2/2)\u00B0 = ${r2d(Math.acos(2**(-0.5)))}\u00B0"
|
||||
println "atan(1) = ${Math.atan(1)} == atan(1)\u00B0 = ${r2d(Math.atan(1))}\u00B0"
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
fromDegrees :: Floating a => a -> a
|
||||
fromDegrees deg = deg * pi / 180
|
||||
|
||||
toDegrees :: Floating a => a -> a
|
||||
toDegrees rad = rad * 180 / pi
|
||||
|
||||
main :: IO ()
|
||||
main =
|
||||
mapM_
|
||||
print
|
||||
[ sin (pi / 6)
|
||||
, sin (fromDegrees 30)
|
||||
, cos (pi / 6)
|
||||
, cos (fromDegrees 30)
|
||||
, tan (pi / 6)
|
||||
, tan (fromDegrees 30)
|
||||
, asin 0.5
|
||||
, toDegrees (asin 0.5)
|
||||
, acos 0.5
|
||||
, toDegrees (acos 0.5)
|
||||
, atan 0.5
|
||||
, toDegrees (atan 0.5)
|
||||
]
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
pi = 4.0 * ATAN(1.0)
|
||||
dtor = pi / 180.0
|
||||
rtod = 180.0 / pi
|
||||
radians = pi / 4.0
|
||||
degrees = 45.0
|
||||
|
||||
WRITE(ClipBoard) SIN(radians), SIN(degrees*dtor)
|
||||
WRITE(ClipBoard) COS(radians), COS(degrees*dtor)
|
||||
WRITE(ClipBoard) TAN(radians), TAN(degrees*dtor)
|
||||
WRITE(ClipBoard) ASIN(SIN(radians)), ASIN(SIN(degrees*dtor))*rtod
|
||||
WRITE(ClipBoard) ACOS(COS(radians)), ACOS(COS(degrees*dtor))*rtod
|
||||
WRITE(ClipBoard) ATAN(TAN(radians)), ATAN(TAN(degrees*dtor))*rtod
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
0.7071067812 0.7071067812
|
||||
0.7071067812 0.7071067812
|
||||
1 1
|
||||
0.7853981634 45
|
||||
0.7853981634 45
|
||||
0.7853981634 45
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
deg = 35 ; arbitrary number of degrees
|
||||
rad = !dtor*deg ; system variables !dtor and !radeg convert between rad and deg
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
; the trig functions receive and emit radians:
|
||||
print, rad, sin(rad), asin(sin(rad))
|
||||
print, cos(rad), acos(cos(rad))
|
||||
print, tan(rad), atan(tan(rad)) ; etc
|
||||
|
||||
; prints the following:
|
||||
; 0.610865 0.573576 0.610865
|
||||
; 0.819152 0.610865
|
||||
; 0.700208 0.610865
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
; the hyperbolic versions exist and behave as expected:
|
||||
print, sinh(rad) ; etc
|
||||
|
||||
; outputs
|
||||
; 0.649572
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
;If the input is an array, the output has the same dimensions etc as the input:
|
||||
x = !dpi/[[2,3],[4,5],[6,7]] ; !dpi is a read-only sysvar = 3.1415...
|
||||
print,sin(x)
|
||||
|
||||
;outputs:
|
||||
; 1.0000000 0.86602540
|
||||
; 0.70710678 0.58778525
|
||||
; 0.50000000 0.43388374
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
; the trig functions behave as expected for complex arguments:
|
||||
x = complex(1,2)
|
||||
print,sin(x)
|
||||
|
||||
; outputs
|
||||
; ( 3.16578, 1.95960)
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
100 LET DG=DEG(PI/4)
|
||||
110 OPTION ANGLE DEGREES
|
||||
120 PRINT SIN(DG)
|
||||
130 PRINT COS(DG)
|
||||
140 PRINT TAN(DG)
|
||||
150 PRINT ASIN(SIN(DG))
|
||||
160 PRINT ACOS(COS(DG))
|
||||
170 PRINT ATN(TAN(DG))
|
||||
180 LET RD=RAD(45)
|
||||
190 OPTION ANGLE RADIANS
|
||||
200 PRINT SIN(RD)
|
||||
210 PRINT COS(RD)
|
||||
220 PRINT TAN(RD)
|
||||
230 PRINT ASIN(SIN(RD))
|
||||
240 PRINT ACOS(COS(RD))
|
||||
250 PRINT ATN(TAN(RD))
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
invocable all
|
||||
procedure main()
|
||||
|
||||
d := 30 # degrees
|
||||
r := dtor(d) # convert to radians
|
||||
|
||||
every write(f := !["sin","cos","tan"],"(",r,")=",y := f(r)," ",fi := "a" || f,"(",y,")=",x := fi(y)," rad = ",rtod(x)," deg")
|
||||
end
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
(1&o. , 2&o. ,: 3&o.) (4 %~ o. 1) , 180 %~ o. 45
|
||||
0.707107 0.707107
|
||||
0.707107 0.707107
|
||||
1 1
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
([ ,. 180p_1&*) (_1&o. , _2&o. ,: _3&o.) 0.5
|
||||
0.523599 30
|
||||
1.0472 60
|
||||
0.463648 26.5651
|
||||
10
Task/Trigonometric-functions/J/trigonometric-functions-3.j
Normal file
10
Task/Trigonometric-functions/J/trigonometric-functions-3.j
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
require 'trig'
|
||||
(sin , cos ,: tan) (1p1 % 4), rfd 45
|
||||
0.707107 0.707107
|
||||
0.707107 0.707107
|
||||
1 1
|
||||
|
||||
([ ,. dfr) (arcsin , arccos ,: arctan) 0.5
|
||||
0.523599 30
|
||||
1.0472 60
|
||||
0.463648 26.5651
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
public class Trig {
|
||||
public static void main(String[] args) {
|
||||
//Pi / 4 is 45 degrees. All answers should be the same.
|
||||
double radians = Math.PI / 4;
|
||||
double degrees = 45.0;
|
||||
//sine
|
||||
System.out.println(Math.sin(radians) + " " + Math.sin(Math.toRadians(degrees)));
|
||||
//cosine
|
||||
System.out.println(Math.cos(radians) + " " + Math.cos(Math.toRadians(degrees)));
|
||||
//tangent
|
||||
System.out.println(Math.tan(radians) + " " + Math.tan(Math.toRadians(degrees)));
|
||||
//arcsine
|
||||
double arcsin = Math.asin(Math.sin(radians));
|
||||
System.out.println(arcsin + " " + Math.toDegrees(arcsin));
|
||||
//arccosine
|
||||
double arccos = Math.acos(Math.cos(radians));
|
||||
System.out.println(arccos + " " + Math.toDegrees(arccos));
|
||||
//arctangent
|
||||
double arctan = Math.atan(Math.tan(radians));
|
||||
System.out.println(arctan + " " + Math.toDegrees(arctan));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
var
|
||||
radians = Math.PI / 4, // Pi / 4 is 45 degrees. All answers should be the same.
|
||||
degrees = 45.0,
|
||||
sine = Math.sin(radians),
|
||||
cosine = Math.cos(radians),
|
||||
tangent = Math.tan(radians),
|
||||
arcsin = Math.asin(sine),
|
||||
arccos = Math.acos(cosine),
|
||||
arctan = Math.atan(tangent);
|
||||
|
||||
// sine
|
||||
window.alert(sine + " " + Math.sin(degrees * Math.PI / 180));
|
||||
// cosine
|
||||
window.alert(cosine + " " + Math.cos(degrees * Math.PI / 180));
|
||||
// tangent
|
||||
window.alert(tangent + " " + Math.tan(degrees * Math.PI / 180));
|
||||
// arcsine
|
||||
window.alert(arcsin + " " + (arcsin * 180 / Math.PI));
|
||||
// arccosine
|
||||
window.alert(arccos + " " + (arccos * 180 / Math.PI));
|
||||
// arctangent
|
||||
window.alert(arctan + " " + (arctan * 180 / Math.PI));
|
||||
25
Task/Trigonometric-functions/Jq/trigonometric-functions-1.jq
Normal file
25
Task/Trigonometric-functions/Jq/trigonometric-functions-1.jq
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
# degrees to radians
|
||||
def radians:
|
||||
(-1|acos) as $pi | (. * $pi / 180);
|
||||
|
||||
def task:
|
||||
(-1|acos) as $pi
|
||||
| ($pi / 180) as $degrees
|
||||
| "Using radians:",
|
||||
" sin(-pi / 6) = \( (-$pi / 6) | sin )",
|
||||
" cos(3 * pi / 4) = \( (3 * $pi / 4) | cos)",
|
||||
" tan(pi / 3) = \( ($pi / 3) | tan)",
|
||||
" asin(-1 / 2) = \((-1 / 2) | asin)",
|
||||
" acos(-sqrt(2)/2) = \((-(2|sqrt)/2) | acos )",
|
||||
" atan(sqrt(3)) = \( 3 | sqrt | atan )",
|
||||
|
||||
"Using degrees:",
|
||||
" sin(-30) = \((-30 * $degrees) | sin)",
|
||||
" cos(135) = \((135 * $degrees) | cos)",
|
||||
" tan(60) = \(( 60 * $degrees) | tan)",
|
||||
" asin(-1 / 2) = \( (-1 / 2) | asin / $degrees)",
|
||||
" acos(-sqrt(2)/2) = \( (-(2|sqrt) / 2) | acos / $degrees)",
|
||||
" atan(sqrt(3)) = \( (3 | sqrt) | atan / $degrees)"
|
||||
;
|
||||
|
||||
task
|
||||
14
Task/Trigonometric-functions/Jq/trigonometric-functions-2.jq
Normal file
14
Task/Trigonometric-functions/Jq/trigonometric-functions-2.jq
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
Using radians:
|
||||
sin(-pi / 6) = -0.49999999999999994
|
||||
cos(3 * pi / 4) = -0.7071067811865475
|
||||
tan(pi / 3) = 1.7320508075688767
|
||||
asin(-1 / 2) = -0.5235987755982988
|
||||
acos(-sqrt(2)/2) = 2.356194490192345
|
||||
atan(sqrt(3)) = 1.0471975511965979
|
||||
Using degrees:
|
||||
sin(-30) = -0.49999999999999994
|
||||
cos(135) = -0.7071067811865475
|
||||
tan(60) = 1.7320508075688767
|
||||
asin(-1 / 2) = -29.999999999999996
|
||||
acos(-sqrt(2)/2) = 135
|
||||
atan(sqrt(3)) = 60.00000000000001
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
/* Trig in Jsish */
|
||||
var x;
|
||||
|
||||
;x = Math.PI / 4;
|
||||
;Math.sin(x);
|
||||
;Math.cos(x);
|
||||
;Math.tan(x);
|
||||
;Math.asin(Math.sin(x)) * 4;
|
||||
;Math.acos(Math.cos(x)) * 4;
|
||||
;Math.atan(Math.tan(x));
|
||||
;Math.atan2(Math.tan(x), 1.0);
|
||||
;Math.atan2(Math.tan(x), -1.0);
|
||||
|
||||
;x = 45.0;
|
||||
;Math.sin(x * Math.PI / 180);
|
||||
;Math.cos(x * Math.PI / 180);
|
||||
;Math.tan(x * Math.PI / 180);
|
||||
|
||||
/*
|
||||
=!EXPECTSTART!=
|
||||
x = Math.PI / 4 ==> 0.7853981633974483
|
||||
Math.sin(x) ==> 0.7071067811865475
|
||||
Math.cos(x) ==> 0.7071067811865476
|
||||
Math.tan(x) ==> 0.9999999999999999
|
||||
Math.asin(Math.sin(x)) * 4 ==> 3.141592653589793
|
||||
Math.acos(Math.cos(x)) * 4 ==> 3.141592653589793
|
||||
Math.atan(Math.tan(x)) ==> 0.7853981633974483
|
||||
Math.atan2(Math.tan(x), 1.0) ==> 0.7853981633974483
|
||||
Math.atan2(Math.tan(x), -1.0) ==> 2.356194490192345
|
||||
x = 45.0 ==> 45
|
||||
Math.sin(x * Math.PI / 180) ==> 0.7071067811865475
|
||||
Math.cos(x * Math.PI / 180) ==> 0.7071067811865476
|
||||
Math.tan(x * Math.PI / 180) ==> 0.9999999999999999
|
||||
=!EXPECTEND!=
|
||||
*/
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
# v0.6.0
|
||||
|
||||
rad = π / 4
|
||||
deg = 45.0
|
||||
|
||||
@show rad deg
|
||||
@show sin(rad) sin(deg2rad(deg))
|
||||
@show cos(rad) cos(deg2rad(deg))
|
||||
@show tan(rad) tan(deg2rad(deg))
|
||||
@show asin(sin(rad)) asin(sin(rad)) |> rad2deg
|
||||
@show acos(cos(rad)) acos(cos(rad)) |> rad2deg
|
||||
@show atan(tan(rad)) atan(tan(rad)) |> rad2deg
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
import kotlin.math.*
|
||||
|
||||
fun main() {
|
||||
fun Double.toDegrees() = this * 180 / PI
|
||||
val angle = PI / 4
|
||||
|
||||
println("angle = $angle rad = ${angle.toDegrees()}°")
|
||||
val sine = sin(angle)
|
||||
println("sin(angle) = $sine")
|
||||
val cosine = cos(angle)
|
||||
println("cos(angle) = $cosine")
|
||||
val tangent = tan(angle)
|
||||
println("tan(angle) = $tangent")
|
||||
println()
|
||||
|
||||
val asin = asin(sine)
|
||||
println("asin(sin(angle)) = $asin rad = ${asin.toDegrees()}°")
|
||||
val acos = acos(cosine)
|
||||
println("acos(cos(angle)) = $acos rad = ${acos.toDegrees()}°")
|
||||
val atan = atan(tangent)
|
||||
println("atan(tan(angle)) = $atan rad = ${atan.toDegrees()}°")
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
{def deg2rad {lambda {:d} {* {/ {PI} 180} :d}}}
|
||||
-> deg2rad
|
||||
{def rad2deg {lambda {:r} {* {/ 180 {PI}} :r}}}
|
||||
-> rad2deg
|
||||
|
||||
{deg2rad 180}
|
||||
-> 3.141592653589793 = PI
|
||||
{rad2deg {PI}}°
|
||||
-> 180°
|
||||
|
||||
{sin {deg2rad 45}}
|
||||
-> 0.7071067811865475 = PI/4
|
||||
{cos {deg2rad 45}}
|
||||
-> 0.7071067811865476 = PI/4
|
||||
{tan {deg2rad 45}}
|
||||
-> 0.9999999999999999 = 1
|
||||
|
||||
{rad2deg {asin 0.5}}° -> 30.000000000000004°
|
||||
{rad2deg {acos 0.5}}° -> 60.00000000000001°
|
||||
{rad2deg {atan 1}}° -> 45°
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
pi = ACS(-1)
|
||||
radians = pi / 4.0
|
||||
rtod = 180 / pi
|
||||
degrees = radians * rtod
|
||||
dtor = pi / 180
|
||||
|
||||
'LB works in radians, so degrees require conversion
|
||||
print "Sin: ";SIN(radians);" "; SIN(degrees*dtor)
|
||||
print "Cos: ";COS(radians);" "; COS(degrees*dtor)
|
||||
print "Tan: ";TAN(radians);" ";TAN(degrees*dtor)
|
||||
print "- Inverse functions:"
|
||||
print "Asn: ";ASN(SIN(radians));" Rad, "; ASN(SIN(degrees*dtor))*rtod;" Deg"
|
||||
print "Acs: ";ACS(COS(radians));" Rad, "; ACS(COS(degrees*dtor))*rtod;" Deg"
|
||||
print "Atn: ";ATN(TAN(radians));" Rad, "; ATN(TAN(degrees*dtor))*rtod;" Deg"
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
print sin 45
|
||||
print cos 45
|
||||
print arctan 1
|
||||
make "pi (radarctan 0 1) * 2 ; based on quadrant if uses two parameters
|
||||
print radsin :pi / 4
|
||||
print radcos :pi / 4
|
||||
print 4 * radarctan 1
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
print sin 45
|
||||
print cos 45
|
||||
print arctan 1
|
||||
print radsin pi / 4
|
||||
print radcos pi / 4
|
||||
print 4 * radarctan 1
|
||||
|
|
@ -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.
|
||||
|
|
@ -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
|
||||
|
|
@ -0,0 +1 @@
|
|||
print(math.cos(1), math.sin(1), math.tan(1), math.atan(1), math.atan2(3, 4))
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
function trigExample(angleDegrees)
|
||||
|
||||
angleRadians = angleDegrees * (pi/180);
|
||||
|
||||
disp(sprintf('sin(%f)= %f\nasin(%f)= %f',[angleRadians sin(angleRadians) sin(angleRadians) asin(sin(angleRadians))]));
|
||||
disp(sprintf('sind(%f)= %f\narcsind(%f)= %f',[angleDegrees sind(angleDegrees) sind(angleDegrees) asind(sind(angleDegrees))]));
|
||||
disp('-----------------------');
|
||||
disp(sprintf('cos(%f)= %f\nacos(%f)= %f',[angleRadians cos(angleRadians) cos(angleRadians) acos(cos(angleRadians))]));
|
||||
disp(sprintf('cosd(%f)= %f\narccosd(%f)= %f',[angleDegrees cosd(angleDegrees) cosd(angleDegrees) acosd(cosd(angleDegrees))]));
|
||||
disp('-----------------------');
|
||||
disp(sprintf('tan(%f)= %f\natan(%f)= %f',[angleRadians tan(angleRadians) tan(angleRadians) atan(tan(angleRadians))]));
|
||||
disp(sprintf('tand(%f)= %f\narctand(%f)= %f',[angleDegrees tand(angleDegrees) tand(angleDegrees) atand(tand(angleDegrees))]));
|
||||
end
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
>> trigExample(78)
|
||||
sin(1.361357)= 0.978148
|
||||
asin(0.978148)= 1.361357
|
||||
sind(78.000000)= 0.978148
|
||||
arcsind(0.978148)= 78.000000
|
||||
-----------------------
|
||||
cos(1.361357)= 0.207912
|
||||
acos(0.207912)= 1.361357
|
||||
cosd(78.000000)= 0.207912
|
||||
arccosd(0.207912)= 78.000000
|
||||
-----------------------
|
||||
tan(1.361357)= 4.704630
|
||||
atan(4.704630)= 1.361357
|
||||
tand(78.000000)= 4.704630
|
||||
arctand(4.704630)= 78.000000
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
local radians = pi / 4
|
||||
local degrees = 45.0
|
||||
|
||||
--sine
|
||||
print (sin (radToDeg radians))
|
||||
print (sin degrees)
|
||||
--cosine
|
||||
print (cos (radToDeg radians))
|
||||
print (cos degrees)
|
||||
--tangent
|
||||
print (tan (radToDeg radians))
|
||||
print (tan degrees)
|
||||
--arcsine
|
||||
print (asin (sin (radToDeg radians)))
|
||||
print (asin (sin degrees))
|
||||
--arccosine
|
||||
print (acos (cos (radToDeg radians)))
|
||||
print (acos (cos degrees))
|
||||
--arctangent
|
||||
print (atan (tan (radToDeg radians)))
|
||||
print (atan (tan degrees))
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
sin(Pi/3);
|
||||
cos(Pi/3);
|
||||
tan(Pi/3);
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
with(Units[Standard]):
|
||||
sin(60*Unit(degree));
|
||||
cos(60*Unit(degree));
|
||||
tan(60*Unit(degree));
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
csc(Pi/3);
|
||||
sec(Pi/3);
|
||||
cot(Pi/3);
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
arcsin(1);
|
||||
arccos(1);
|
||||
arctan(1);
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
Sin[1]
|
||||
Cos[1]
|
||||
Tan[1]
|
||||
ArcSin[1]
|
||||
ArcCos[1]
|
||||
ArcTan[1]
|
||||
Sin[90 Degree]
|
||||
Cos[90 Degree]
|
||||
Tan[90 Degree]
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
a: %pi / 3;
|
||||
[sin(a), cos(a), tan(a), sec(a), csc(a), cot(a)];
|
||||
|
||||
b: 1 / 2;
|
||||
[asin(b), acos(b), atan(b), asec(1 / b), acsc(1 / b), acot(b)];
|
||||
|
||||
/* Hyperbolic functions are also available */
|
||||
a: 1 / 2;
|
||||
[sinh(a), cosh(a), tanh(a), sech(a), csch(a), coth(a)], numer;
|
||||
[asinh(a), acosh(1 / a), atanh(a), asech(a), acsch(a), acoth(1 / a)], numer;
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
Pi := 3.14159;
|
||||
vardef torad expr x = Pi*x/180 enddef; % conversions
|
||||
vardef todeg expr x = 180x/Pi enddef;
|
||||
vardef sin expr x = sind(todeg(x)) enddef; % radians version of sind
|
||||
vardef cos expr x = cosd(todeg(x)) enddef; % and cosd
|
||||
|
||||
vardef sign expr x = if x>=0: 1 else: -1 fi enddef; % commodity
|
||||
|
||||
vardef tand expr x = % tan with arg in degree
|
||||
if cosd(x) = 0:
|
||||
infinity * sign(sind(x))
|
||||
else: sind(x)/cosd(x) fi enddef;
|
||||
vardef tan expr x = tand(todeg(x)) enddef; % arg in rad
|
||||
|
||||
% INVERSE
|
||||
|
||||
% the arc having x as tanget is that between x-axis and a line
|
||||
% from the center to the point (1, x); MF angle says this
|
||||
vardef atand expr x = angle(1,x) enddef;
|
||||
vardef atan expr x = torad(atand(x)) enddef; % rad version
|
||||
|
||||
% known formula to express asin and acos in function of
|
||||
% atan; a+-+b stays for sqrt(a^2 - b^2) (defined in plain MF)
|
||||
vardef asin expr x = 2atan(x/(1+(1+-+x))) enddef;
|
||||
vardef acos expr x = 2atan((1+-+x)/(1+x)) enddef;
|
||||
|
||||
vardef asind expr x = todeg(asin(x)) enddef; % degree versions
|
||||
vardef acosd expr x = todeg(acos(x)) enddef;
|
||||
|
||||
% commodity
|
||||
def outcompare(expr a, b) = message decimal a & " = " & decimal b enddef;
|
||||
|
||||
% output tests
|
||||
outcompare(torad(60), Pi/3);
|
||||
outcompare(todeg(Pi/6), 30);
|
||||
|
||||
outcompare(Pi/3, asin(sind(60)));
|
||||
outcompare(30, acosd(cos(Pi/6)));
|
||||
outcompare(45, atand(tand(45)));
|
||||
outcompare(Pi/4, atan(tand(45)));
|
||||
|
||||
outcompare(sin(Pi/3), sind(60));
|
||||
outcompare(cos(Pi/4), cosd(45));
|
||||
outcompare(tan(Pi/3), tand(60));
|
||||
|
||||
end
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
pi3 = pi/3
|
||||
degToRad = pi/180
|
||||
print "sin PI/3 radians = " + sin(pi3)
|
||||
print "sin 60 degrees = " + sin(60*degToRad)
|
||||
print "arcsin 0.5 in radians = " + asin(0.5)
|
||||
print "arcsin 0.5 in degrees = " + asin(0.5)/degToRad
|
||||
print "cos PI/3 radians = " + cos(pi3)
|
||||
print "cos 60 degrees = " + cos(60*degToRad)
|
||||
print "arccos 0.5 in radians = " + acos(0.5)
|
||||
print "arccos 0.5 in degrees = " + acos(0.5)/degToRad
|
||||
print "tan PI/3 radians = " + tan(pi3)
|
||||
print "tan 60 degrees = " + tan(60*degToRad)
|
||||
print "arctan 0.5 in radians = " + atan(0.5)
|
||||
print "arctan 0.5 in degrees = " + atan(0.5)/degToRad
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
MODULE Trig;
|
||||
FROM RealMath IMPORT pi,sin,cos,tan,arctan,arccos,arcsin;
|
||||
FROM RealStr IMPORT RealToStr;
|
||||
FROM Terminal IMPORT WriteString,WriteLn,ReadChar;
|
||||
|
||||
PROCEDURE WriteReal(v : REAL);
|
||||
VAR buf : ARRAY[0..31] OF CHAR;
|
||||
BEGIN
|
||||
RealToStr(v, buf);
|
||||
WriteString(buf)
|
||||
END WriteReal;
|
||||
|
||||
VAR theta : REAL;
|
||||
BEGIN
|
||||
theta := pi / 4.0;
|
||||
|
||||
WriteString("theta: ");
|
||||
WriteReal(theta);
|
||||
WriteLn;
|
||||
|
||||
WriteString("sin: ");
|
||||
WriteReal(sin(theta));
|
||||
WriteLn;
|
||||
|
||||
WriteString("cos: ");
|
||||
WriteReal(cos(theta));
|
||||
WriteLn;
|
||||
|
||||
WriteString("tan: ");
|
||||
WriteReal(tan(theta));
|
||||
WriteLn;
|
||||
|
||||
WriteString("arcsin: ");
|
||||
WriteReal(arcsin(sin(theta)));
|
||||
WriteLn;
|
||||
|
||||
WriteString("arccos: ");
|
||||
WriteReal(arccos(cos(theta)));
|
||||
WriteLn;
|
||||
|
||||
WriteString("arctan: ");
|
||||
WriteReal(arctan(tan(theta)));
|
||||
WriteLn;
|
||||
|
||||
ReadChar
|
||||
END Trig.
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
/* NetRexx */
|
||||
options replace format comments java crossref symbols nobinary utf8
|
||||
|
||||
numeric digits 30
|
||||
|
||||
parse 'Radians Degrees angle' RADIANS DEGREES ANGLE .;
|
||||
parse 'sine cosine tangent arcsine arccosine arctangent' SINE COSINE TANGENT ARCSINE ARCCOSINE ARCTANGENT .
|
||||
|
||||
trigVals = ''
|
||||
trigVals[RADIANS, ANGLE ] = (Rexx Math.PI) / 4 -- Pi/4 == 45 degrees
|
||||
trigVals[DEGREES, ANGLE ] = 45.0
|
||||
trigVals[RADIANS, SINE ] = (Rexx Math.sin(trigVals[RADIANS, ANGLE]))
|
||||
trigVals[DEGREES, SINE ] = (Rexx Math.sin(Math.toRadians(trigVals[DEGREES, ANGLE])))
|
||||
trigVals[RADIANS, COSINE ] = (Rexx Math.cos(trigVals[RADIANS, ANGLE]))
|
||||
trigVals[DEGREES, COSINE ] = (Rexx Math.cos(Math.toRadians(trigVals[DEGREES, ANGLE])))
|
||||
trigVals[RADIANS, TANGENT ] = (Rexx Math.tan(trigVals[RADIANS, ANGLE]))
|
||||
trigVals[DEGREES, TANGENT ] = (Rexx Math.tan(Math.toRadians(trigVals[DEGREES, ANGLE])))
|
||||
trigVals[RADIANS, ARCSINE ] = (Rexx Math.asin(trigVals[RADIANS, SINE]))
|
||||
trigVals[DEGREES, ARCSINE ] = (Rexx Math.toDegrees(Math.acos(trigVals[DEGREES, SINE])))
|
||||
trigVals[RADIANS, ARCCOSINE ] = (Rexx Math.acos(trigVals[RADIANS, COSINE]))
|
||||
trigVals[DEGREES, ARCCOSINE ] = (Rexx Math.toDegrees(Math.acos(trigVals[DEGREES, COSINE])))
|
||||
trigVals[RADIANS, ARCTANGENT] = (Rexx Math.atan(trigVals[RADIANS, TANGENT]))
|
||||
trigVals[DEGREES, ARCTANGENT] = (Rexx Math.toDegrees(Math.atan(trigVals[DEGREES, TANGENT])))
|
||||
|
||||
say ' '.right(12)'|' RADIANS.right(17) '|' DEGREES.right(17) '|'
|
||||
say ANGLE.right(12)'|' trigVals[RADIANS, ANGLE ].format(4, 12) '|' trigVals[DEGREES, ANGLE ].format(4, 12) '|'
|
||||
say SINE.right(12)'|' trigVals[RADIANS, SINE ].format(4, 12) '|' trigVals[DEGREES, SINE ].format(4, 12) '|'
|
||||
say COSINE.right(12)'|' trigVals[RADIANS, COSINE ].format(4, 12) '|' trigVals[DEGREES, COSINE ].format(4, 12) '|'
|
||||
say TANGENT.right(12)'|' trigVals[RADIANS, TANGENT ].format(4, 12) '|' trigVals[DEGREES, TANGENT ].format(4, 12) '|'
|
||||
say ARCSINE.right(12)'|' trigVals[RADIANS, ARCSINE ].format(4, 12) '|' trigVals[DEGREES, ARCSINE ].format(4, 12) '|'
|
||||
say ARCCOSINE.right(12)'|' trigVals[RADIANS, ARCCOSINE ].format(4, 12) '|' trigVals[DEGREES, ARCCOSINE ].format(4, 12) '|'
|
||||
say ARCTANGENT.right(12)'|' trigVals[RADIANS, ARCTANGENT].format(4, 12) '|' trigVals[DEGREES, ARCTANGENT].format(4, 12) '|'
|
||||
say
|
||||
|
||||
return
|
||||
11
Task/Trigonometric-functions/Nim/trigonometric-functions.nim
Normal file
11
Task/Trigonometric-functions/Nim/trigonometric-functions.nim
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
import math, strformat
|
||||
|
||||
let rad = Pi/4
|
||||
let deg = 45.0
|
||||
|
||||
echo &"Sine: {sin(rad):.10f} {sin(degToRad(deg)):13.10f}"
|
||||
echo &"Cosine : {cos(rad):.10f} {cos(degToRad(deg)):13.10f}"
|
||||
echo &"Tangent: {tan(rad):.10f} {tan(degToRad(deg)):13.10f}"
|
||||
echo &"Arcsine: {arcsin(sin(rad)):.10f} {radToDeg(arcsin(sin(degToRad(deg)))):13.10f}"
|
||||
echo &"Arccosine: {arccos(cos(rad)):.10f} {radToDeg(arccos(cos(degToRad(deg)))):13.10f}"
|
||||
echo &"Arctangent: {arctan(tan(rad)):.10f} {radToDeg(arctan(tan(degToRad(deg)))):13.10f}"
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
let pi = 4. *. atan 1.
|
||||
|
||||
let radians = pi /. 4.
|
||||
let degrees = 45.;;
|
||||
|
||||
Printf.printf "%f %f\n" (sin radians) (sin (degrees *. pi /. 180.));;
|
||||
Printf.printf "%f %f\n" (cos radians) (cos (degrees *. pi /. 180.));;
|
||||
Printf.printf "%f %f\n" (tan radians) (tan (degrees *. pi /. 180.));;
|
||||
let arcsin = asin (sin radians);;
|
||||
Printf.printf "%f %f\n" arcsin (arcsin *. 180. /. pi);;
|
||||
let arccos = acos (cos radians);;
|
||||
Printf.printf "%f %f\n" arccos (arccos *. 180. /. pi);;
|
||||
let arctan = atan (tan radians);;
|
||||
Printf.printf "%f %f\n" arctan (arctan *. 180. /. pi);;
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
function d = degree(rad)
|
||||
d = 180*rad/pi;
|
||||
endfunction
|
||||
|
||||
r = pi/3;
|
||||
rd = degree(r);
|
||||
|
||||
funcs = { "sin", "cos", "tan", "sec", "cot", "csc" };
|
||||
ifuncs = { "asin", "acos", "atan", "asec", "acot", "acsc" };
|
||||
|
||||
for i = 1 : numel(funcs)
|
||||
v = arrayfun(funcs{i}, r);
|
||||
vd = arrayfun(strcat(funcs{i}, "d"), rd);
|
||||
iv = arrayfun(ifuncs{i}, v);
|
||||
ivd = arrayfun(strcat(ifuncs{i}, "d"), vd);
|
||||
printf("%s(%f) = %s(%f) = %f (%f)\n",
|
||||
funcs{i}, r, strcat(funcs{i}, "d"), rd, v, vd);
|
||||
printf("%s(%f) = %f\n%s(%f) = %f\n",
|
||||
ifuncs{i}, v, iv,
|
||||
strcat(ifuncs{i}, "d"), vd, ivd);
|
||||
endfor
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
import: math
|
||||
|
||||
: testTrigo
|
||||
| rad deg hyp z |
|
||||
Pi 4 / ->rad
|
||||
45.0 ->deg
|
||||
0.5 ->hyp
|
||||
|
||||
System.Out rad sin << " - " << deg asRadian sin << cr
|
||||
System.Out rad cos << " - " << deg asRadian cos << cr
|
||||
System.Out rad tan << " - " << deg asRadian tan << cr
|
||||
|
||||
printcr
|
||||
|
||||
rad sin asin ->z
|
||||
System.Out z << " - " << z asDegree << cr
|
||||
|
||||
rad cos acos ->z
|
||||
System.Out z << " - " << z asDegree << cr
|
||||
|
||||
rad tan atan ->z
|
||||
System.Out z << " - " << z asDegree << cr
|
||||
|
||||
printcr
|
||||
|
||||
System.Out hyp sinh << " - " << hyp sinh asinh << cr
|
||||
System.Out hyp cosh << " - " << hyp cosh acosh << cr
|
||||
System.Out hyp tanh << " - " << hyp tanh atanh << cr ;
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
/* REXX ---------------------------------------------------------------
|
||||
* show how the functions can be used
|
||||
* 03.05.2014 Walter Pachl
|
||||
*--------------------------------------------------------------------*/
|
||||
Say 'Default precision:' .locaL~my.rxm~precision()
|
||||
Say 'Default type: ' .locaL~my.rxm~type()
|
||||
Say 'rxmsin(60) ='rxmsin(60) -- use default precision and type
|
||||
Say 'rxmsin(1,21,"R")='rxmsin(1,21,'R') -- precision and type specified
|
||||
Say 'rxmlog(-1) ='rxmlog(-1)
|
||||
Say 'rxmlog( 0) ='rxmlog( 0)
|
||||
Say 'rxmlog( 1) ='rxmlog( 1)
|
||||
Say 'rxmlog( 2) ='rxmlog( 2)
|
||||
.locaL~my.rxm~precision=50
|
||||
.locaL~my.rxm~type='R'
|
||||
Say 'Changed precision:' .locaL~my.rxm~precision()
|
||||
Say 'Changed type: ' .locaL~my.rxm~type()
|
||||
Say 'rxmsin(1) ='rxmsin(1) -- use changed precision and type
|
||||
::requires rxm.cls
|
||||
1032
Task/Trigonometric-functions/OoRexx/trigonometric-functions-2.rexx
Normal file
1032
Task/Trigonometric-functions/OoRexx/trigonometric-functions-2.rexx
Normal file
File diff suppressed because it is too large
Load diff
21
Task/Trigonometric-functions/Oz/trigonometric-functions.oz
Normal file
21
Task/Trigonometric-functions/Oz/trigonometric-functions.oz
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
declare
|
||||
PI = 3.14159265
|
||||
|
||||
fun {FromDegrees Deg}
|
||||
Deg * PI / 180.
|
||||
end
|
||||
|
||||
fun {ToDegrees Rad}
|
||||
Rad * 180. / PI
|
||||
end
|
||||
|
||||
Radians = PI / 4.
|
||||
Degrees = 45.
|
||||
in
|
||||
for F in [Sin Cos Tan] do
|
||||
{System.showInfo {F Radians}#" "#{F {FromDegrees Degrees}}}
|
||||
end
|
||||
|
||||
for I#F in [Asin#Sin Acos#Cos Atan#Tan] do
|
||||
{System.showInfo {I {F Radians}}#" "#{ToDegrees {I {F Radians}}}}
|
||||
end
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
cos(Pi/2)
|
||||
sin(Pi/2)
|
||||
tan(Pi/2)
|
||||
acos(1)
|
||||
asin(1)
|
||||
atan(1)
|
||||
|
|
@ -0,0 +1 @@
|
|||
apply(f->f(1), [cos,sin,tan,acos,asin,atan])
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
$radians = M_PI / 4;
|
||||
$degrees = 45 * M_PI / 180;
|
||||
echo sin($radians) . " " . sin($degrees);
|
||||
echo cos($radians) . " " . cos($degrees);
|
||||
echo tan($radians) . " " . tan($degrees);
|
||||
echo asin(sin($radians)) . " " . asin(sin($radians)) * 180 / M_PI;
|
||||
echo acos(cos($radians)) . " " . acos(cos($radians)) * 180 / M_PI;
|
||||
echo atan(tan($radians)) . " " . atan(tan($radians)) * 180 / M_PI;
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
declare (x, xd, y, v) float;
|
||||
|
||||
x = 0.5; xd = 45;
|
||||
|
||||
/* angle in radians: */
|
||||
v = sin(x); y = asin(v); put skip list (y);
|
||||
v = cos(x); y = acos(v); put skip list (y);
|
||||
v = tan(x); y = atan(v); put skip list (y);
|
||||
|
||||
/* angle in degrees: */
|
||||
v = sind(xd); put skip list (v);
|
||||
v = cosd(xd); put skip list (v);
|
||||
v = tand(xd); y = atand(v); put skip list (y);
|
||||
|
||||
/* hyperbolic functions: */
|
||||
v = sinh(x); put skip list (v);
|
||||
v = cosh(x); put skip list (v);
|
||||
v = tanh(x); y = atanh(v); put skip list (y);
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue