- Perl ›
- Numerical value ›
- here

## Use trigonometric functions

Introducing functions and modules for using trigonometric functions.

#### Sign

To find the ** sine **, specify sin function in radians with an angle of π (pi function). Is easy.

use Math::Trig 'pi'; sin(pi/2); cos(pi/3);

(Reference) Math::Trig

#### Cosine

Use cos function to find the ** cosine **.

use Math::Trig 'pi'; cos(pi/3);

### Various trigonometric functions

The only builtin functions related to trigonometric functions are the cos function and the sin function, but the standard module has a trigonometric function-related module called Math::Trig. there is. I will briefly introduce the contents.

#### Tangent

To find the ** tangent **, use the ** tan function ** of the ** Math::Trig ** module.

use Math::Trig qw/tan pi/; tan (pi/4);

#### Reciprocal of trigonometric function

The reciprocal is the number with the denominator and numerator swapped. Note that the inverse function has a different meaning. The reciprocals of sin, cos, and tan are called cosec, sec, and cot, respectively.

You can use the cosec, sec, and cot functions in the Math::Trig module.

Twice | meaning |

cosec | 1/sin |

sec | 1/cos |

cot | 1/tan |

#### Inverse function of trigonometric function

The inverse function is g that satisfies x = g (y) when the relation y = f (x) holds. We read that y = f (x) becomes y when we act on x with f. We read that x = g (y) becomes x when we act on y with g.

In other words, g that causes x to act on f and then returns to x when g is applied is called the inverse function of f. If you write with a symbol

x = g (f (x))

When g exists that satisfies, g is called the inverse function of f.

The inverse functions of sin, cos, and tan are called asin(arc sine), acos(arc cosine), and atan (arc tangent), respectively.

You can use the asin function, acos function, and atan function of the Math::Trig module.

Twice | meaning |

asin | Inverse function of sin |

acos | Inverse function of cos |

atan | Inverse function of tan |

### Example

This is an example to find sin, cos, and tan.

use strict; use warnings; use Math::Trig qw/tan pi/; # sin(90 °) = 1; print "sin(π/2) =" . Sin (pi/2) . "\n"; # cos(60 °) = 1/2; print "cos(π/3) =" . Cos (pi/3) . "\n"; # tan (45 °) = 1; print "tan (π/4) =" . tan (pi/4) . "\n";