Professional Documents
Culture Documents
Lecture 2 - Functions
Lecture 2 - Functions
Lecture 2 - Functions
Functions consist of
Name
Input argument(s)
Output
In-class Demo
Using the Help Feature
As in most computer languages, log(x) is the syntax for the natural log –
there is no ln function defined in MATLAB
log(x): natural log
log10(x): log base 10
abs(x): absolute value
sign(x): plus or minus
exp(x): ex
Elementary Math Functions - Rounding
Functions
round(x)
fix(x)
floor(x)
ceil(x)
Elementary Math Functions - Discrete
Mathematics
sin(x) sine
cos(x) cosine
tan(x) tangent
asin(x) inverse sine
sinh(x) hyperbolic sine
asinh(x) inverse hyperbolic sine
sind(x) sine with degree input
asind(x) inverse sin with degree output
Data Analysis Functions
max(x)
min(x)
mean(x)
median(x)
sum(x)
prod(x)
sort(x)
sortrows(x)
std(x)
var(x)
Sorting Values: sort function
MATLAB is column dominant, so when sort is used with a 2-D matrix, each
column is sorted in ascending order
max and min functions
When the max function is used with a vector (either a row or a column), it
returns the maximum value in the vector
When x is a matrix, the max is found for each column
max and min functions
The max function can also be used to determine where the maximum
occurs
Sorting Values: sortrows function
The sortrows function allows you to sort entire rows, based on the value in a
specified column.
complex(x,y)
real(A)
imag(A)
isreal(A)
conj(A) imaginary
abs(A)
real
angle(A)
Special Values and Miscellaneous
Functions
pi
i,j
Inf
NaN
clock
date
eps
ans
Hint: The function i is the most common of these functions to be unintentionally
renamed by MATLAB users