MySQL COS() Function

The COS() function returns the cosine of a given number, which is expressed in radians.


Syntax

COS(number)

Definition and Usage

  • The COS() function computes the cosine of a number (in radians).
  • The value returned is a number between -1 and 1.

Parameter Values

Parameter Description
number Required. A numeric value (in radians) to calculate the cosine for.

Technical Details

  • Works in: From MySQL 4.0
  • Result: Returns a numeric value (between -1 and 1).

Examples

Example 1: Cosine of a number

SELECT COS(2) AS Result;

Result:

Result: -0.416146836

Explanation: The cosine of 2 radians is -0.416146836.


Example 2: Cosine of Pi

SELECT COS(PI()) AS Result;

Result:

Result: -1

Explanation: The cosine of π radians is -1.


Example 3: Cosine of a specific angle

If you want to calculate the cosine of a particular angle in degrees, you first need to convert it to radians:

SELECT COS(RADIANS(60)) AS Result;

Result:

Result: 0.5

Explanation: 60 degrees is converted to radians and then the cosine is calculated, which is 0.5.


Usage Notes

  1. Radians:

    • The COS() function requires the angle to be provided in radians. If the angle is in degrees, you need to convert it using the RADIANS() function.
  2. Mathematical Context:

    • The cosine function is frequently used in trigonometry, physics, and geometry, especially in calculations involving waves, rotations, and oscillations.

Practical Query Example:

Calculate the cosine of a rotating object at 45 degrees:

SELECT COS(RADIANS(45)) AS CosineOf45Degrees;

Result:

CosineOf45Degrees: 0.707106781

The COS() function is essential for performing trigonometric operations in MySQL when dealing with angular calculations, waves, and various other mathematical computations.


Was this article helpful?