Trigonometric functions: Difference between revisions
Content added Content deleted
(→{{header|Fortran}}: ++ gnu octave) |
|||
Line 282: | Line 282: | ||
COSH(x) ! Hyperbolic cosine |
COSH(x) ! Hyperbolic cosine |
||
TANH(x) ! Hyperbolic tangent</lang> |
TANH(x) ! Hyperbolic tangent</lang> |
||
=={{header|GNU Octave}}== |
|||
<lang octave>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</lang> |
|||
Output: |
|||
<pre>sin(1.047198) = sind(60.000000) = 0.866025 (0.866025) |
|||
asin(0.866025) = 1.047198 |
|||
asind(0.866025) = 60.000000 |
|||
cos(1.047198) = cosd(60.000000) = 0.500000 (0.500000) |
|||
acos(0.500000) = 1.047198 |
|||
acosd(0.500000) = 60.000000 |
|||
tan(1.047198) = tand(60.000000) = 1.732051 (1.732051) |
|||
atan(1.732051) = 1.047198 |
|||
atand(1.732051) = 60.000000 |
|||
sec(1.047198) = secd(60.000000) = 2.000000 (2.000000) |
|||
asec(2.000000) = 1.047198 |
|||
asecd(2.000000) = 60.000000 |
|||
cot(1.047198) = cotd(60.000000) = 0.577350 (0.577350) |
|||
acot(0.577350) = 1.047198 |
|||
acotd(0.577350) = 60.000000 |
|||
csc(1.047198) = cscd(60.000000) = 1.154701 (1.154701) |
|||
acsc(1.154701) = 1.047198 |
|||
acscd(1.154701) = 60.000000</pre> |
|||
(Lacking: sinh, cosh, tanh, coth and inverses) |
|||
=={{header|Haskell}}== |
=={{header|Haskell}}== |