tan
Symbolic tangent function
Syntax
Description
tan( returns the tangent function of
X)X.
Examples
Tangent Function for Numeric and Symbolic Arguments
Depending on its arguments, tan returns
floating-point or exact symbolic results.
Compute the tangent function for these numbers. Because these numbers are not
symbolic objects, tan returns floating-point results.
A = tan([-2, -pi, pi/6, 5*pi/7, 11])
A =
2.1850 0.0000 0.5774 -1.2540 -225.9508Compute the tangent function for the numbers converted to symbolic objects. For
many symbolic (exact) numbers, tan returns unresolved symbolic
calls.
symA = tan(sym([-2, -pi, pi/6, 5*pi/7, 11]))
symA = [ -tan(2), 0, 3^(1/2)/3, -tan((2*pi)/7), tan(11)]
Use vpa to approximate symbolic results with floating-point
numbers:
vpa(symA)
ans = [ 2.1850398632615189916433061023137,... 0,... 0.57735026918962576450914878050196,... -1.2539603376627038375709109783365,... -225.95084645419514202579548320345]
Plot Tangent Function
Plot the tangent function on the interval from to .
syms x fplot(tan(x),[-pi pi]) grid on

Handle Expressions Containing Tangent Function
Many functions, such as diff,
int, taylor, and
rewrite, can handle expressions containing
tan.
Find the first and second derivatives of the tangent function:
syms x diff(tan(x), x) diff(tan(x), x, x)
ans = tan(x)^2 + 1 ans = 2*tan(x)*(tan(x)^2 + 1)
Find the indefinite integral of the tangent function:
int(tan(x), x)
ans = -log(cos(x))
Find the Taylor series expansion of tan(x):
taylor(tan(x), x)
ans = (2*x^5)/15 + x^3/3 + x
Rewrite the tangent function in terms of the sine and cosine functions:
rewrite(tan(x), 'sincos')
ans = sin(x)/cos(x)
Rewrite the tangent function in terms of the exponential function:
rewrite(tan(x), 'exp')
ans = -(exp(x*2i)*1i - 1i)/(exp(x*2i) + 1)
Evaluate Units with tan Function
tan numerically evaluates these units
automatically: radian, degree,
arcmin, arcsec, and
revolution.
Show this behavior by finding the tangent of x degrees
and 2 radians.
u = symunit; syms x f = [x*u.degree 2*u.radian]; tanf = tan(f)
tanf = [ tan((pi*x)/180), tan(2)]
You can calculate tanf by substituting for
x using subs and then using
double or vpa.
