Cosine function

MuPAD® notebooks will be removed in a future release. Use MATLAB® live scripts instead.

MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.




cos(x) represents the cosine function.

Specify the argument x in radians, not in degrees. For example, use π to specify an angle of 180o.

All trigonometric functions are defined for complex arguments.

Floating-point values are returned for floating-point arguments. Floating-point intervals are returned for floating-point interval arguments. Unevaluated function calls are returned for most exact arguments.

Translations by integer multiples of π are eliminated from the argument. Further, arguments that are rational multiples of π lead to simplified results; symmetry relations are used to rewrite the result using an argument from the standard interval . Explicit expressions are returned for the following arguments:


See Example 2.

The result is rewritten in terms of hyperbolic functions, if the argument is a rational multiple of I. See Example 3.

The functions expand and combine implement the addition theorems for the trigonometric functions. See Example 4.

The trigonometric functions do not respond to properties set via assume. Use simplify to take such properties into account. See Example 4.

Use rewrite to rewrite expressions in terms of a specific target function. For example, you can rewrite expressions involving the cosine function in terms of other trigonometric functions and vice versa. See Example 5.

The inverse function is implemented as arccos. See Example 6.

The float attributes are kernel functions, thus, floating-point evaluation is fast.

Environment Interactions

When called with a floating-point argument, the functions are sensitive to the environment variable DIGITS which determines the numerical working precision.


Example 1

Call cos with the following exact and symbolic input arguments:

cos(PI), cos(1), cos(5 + I), cos(PI/2), cos(PI/11), cos(PI/8)

cos(-x), cos(x + PI), cos(x^2 - 4)

Floating-point values are computed for floating-point arguments:

cos(123.4), cos(5.6 + 7.8*I), cos(1.0/10^20)

Floating-point intervals are computed for interval arguments:

cos(0...1), cos(20...30), cos(0...3)

Example 2

Some special values are implemented:

cos(PI/10), cos(2*PI/5), cos(123/8*PI), cos(-PI/12)

Translations by integer multiples of π are eliminated from the argument:

cos(x + 10*PI), cos(3 - PI), cos(x + PI), cos(2 - 10^100*PI)

All arguments that are rational multiples of π are transformed to arguments from the interval :

cos(4/7*PI), cos(-20*PI/9), cos(123/11*PI), cos(-PI/13)

Example 3

Arguments that are rational multiples of I are rewritten in terms of hyperbolic functions:

cos(5*I), cos(5/4*I), cos(-3*I)

For other complex arguments, use expand to rewrite the result:

cos(5*I + 2*PI/3), cos(PI/4 - 5/4*I), cos(-3*I + PI/2)

expand(cos(5*I + 2*PI/3)),
expand(cos(5/4*I - PI/4)),
expand(cos(-3*I + PI/2))

Example 4

The expand function implements the addition theorems:

expand(cos(x + PI/2)), expand(cos(x + y))

The combine function uses these theorems in the other direction, trying to rewrite products of trigonometric functions:

combine(cos(x)*cos(y), sincos)

The trigonometric functions do not immediately respond to properties set via assume:

assume(n, Type::Integer):
cos(n*PI), cos((n + 1/2)*PI)

Use simplify to take such properties into account:

simplify(cos((n + 1/2)*PI))

assume(n, Type::Even):
cos(n*PI + x), simplify(cos(n*PI + x))

y := cos(x + n*PI) + cos(x - n*PI);

delete n, y

Example 5

Use rewrite to obtain a representation in terms of a specific target function:

rewrite(cos(x)*exp(2*I*x), exp);
rewrite(cos(x), tan)

Example 6

The inverse function is implemented as arccos:


Note that arccos(cos(x)) does not necessarily yield x because arccos produces values with real parts in the interval [0,π]:

arccos(cos(4)), arccos(cos(3.2 + I))

Example 7

diff, float, limit, taylor and other system functions handle expressions involving the trigonometric functions:

diff(cos(x^2), x), float(cos(3)*tan(5 + I))

limit((1 - cos(x))/x^2, x = 0)

taylor(cos(x), x = 0)

Return Values

Arithmetical expression or a floating-point interval

Overloaded By


See Also

MuPAD Functions