Main Content


Symbolic cosine function




cos(X) returns the cosine function of X.


Cosine Function for Numeric and Symbolic Arguments

Depending on its arguments, cos returns floating-point or exact symbolic results.

Compute the cosine function for these numbers. Because these numbers are not symbolic objects, cos returns floating-point results.

A = cos([-2, -pi, pi/6, 5*pi/7, 11])
A =
   -0.4161   -1.0000    0.8660   -0.6235    0.0044

Compute the cosine function for the numbers converted to symbolic objects. For many symbolic (exact) numbers, cos returns unresolved symbolic calls.

symA = cos(sym([-2, -pi, pi/6, 5*pi/7, 11]))
symA =
[ cos(2), -1, 3^(1/2)/2, -cos((2*pi)/7), cos(11)]

Use vpa to approximate symbolic results with floating-point numbers:

ans =
[ -0.41614683654714238699756822950076,...

Plot Cosine Function

Plot the cosine function on the interval from -4π to 4π.

syms x
fplot(cos(x),[-4*pi 4*pi])
grid on

Figure contains an axes object. The axes object contains an object of type functionline.

Handle Expressions Containing Cosine Function

Many functions, such as diff, int, taylor, and rewrite, can handle expressions containing cos.

Find the first and second derivatives of the cosine function:

syms x
diff(cos(x), x)
diff(cos(x), x, x)
ans =
ans =

Find the indefinite integral of the cosine function:

int(cos(x), x)
ans =

Find the Taylor series expansion of cos(x):

taylor(cos(x), x)
ans =
x^4/24 - x^2/2 + 1

Rewrite the cosine function in terms of the exponential function:

rewrite(cos(x), 'exp')
ans =
exp(-x*1i)/2 + exp(x*1i)/2

Evaluate Units with cos Function

cos numerically evaluates these units automatically: radian, degree, arcmin, arcsec, and revolution.

Show this behavior by finding the cosine of x degrees and 2 radians.

u = symunit;
syms x
f = [x* 2*u.radian];
cosinf = cos(f)
cosinf =
[ cos((pi*x)/180), cos(2)]

You can calculate cosinf by substituting for x using subs and then using double or vpa.

Input Arguments

collapse all

Input, specified as a symbolic number, scalar variable, matrix variable (since R2021a), expression, or function, or as a vector or matrix of symbolic numbers, scalar variables, expressions, or functions.

More About

collapse all

Cosine Function

The cosine of an angle, α, defined with reference to a right angled triangle is

cos(α)=adjacent sidehypotenuse=bh.

The cosine of a complex argument, α, is


See Also

| | | | | | | | | |

Introduced before R2006a