Skip to main content
Logo image

Section 1.6 Elementary Built-In Math Functions

MATLAB has a very large library of built in functions.
Elementary math functions:
  • sqrt(x)
  • exp(x)
  • abs(x)
  • log(x)
  • log10(x)
  • factorial(n)
Trigonometric math functions
  • sin(x)
  • cos(x)
  • tan(x)
  • cot(x)
  • asin(x)
  • acos(x)
  • atan(x)
  • acot(x)
  • sinh(x)
  • cosh(x)
  • tanh(x)
  • coth(x)
  • Note: addingdto any of the above function names will produce results in degrees, i.e.sind(x)
There are lots of other mathematical built-in functions in MATLAB. Use the help function to learn more.
Many functions can help with various ways of rounding in MATLAB.
Table 1.14. Rounding Functions
Function Description Example
round(x)
round to the nearest integer \((.5 \leq x \lt 1.5 = 1)\)
>> round(17/5) ans = 3
fix(x)
round towards zero (truncate)
>> fix(13/5) ans = 2
ceil(x)
round towards infinity (like fix for x < 0)
>> ceil(11/5) ans = 3
floor(x)
round towards minus infinity (like fix for x > 0)
>> floor(-9/4) ans = -3
rem(x,y)
remainder after x is divided by y
>> rem(13,5) ans = 3
sign(x)
1 if x > 0, -1 if x < 0, and 0 if x = 0
>> sign(5) ans = 1

Activity 1.3.

How do you find the sine of an angle in MATLAB,
  1. where the angle is given in radians (for example, \(sin(\frac{\pi}{6})\))?
  2. where the angle is given in degrees (for example, \(sin(30\deg)\))?