[MUSIC] Now we know enough to study the formal
definition of MATLAB functions. A function's interface with the world is
defined in a header at the beginning, and that header is called
the function “declaration”. The declaration starts
with the “function” keyword. And to remind you that it's a keyword,
MATLAB highlights it for you in blue. Then come the output arguments,
if you have any. If you have more than one, the square brackets are required;
otherwise they can be omitted. And if you have output arguments,
even one of them, then you have to have an equal sign;
otherwise it can be omitted. Next comes the function name. And the same rules apply for
function names as for variable names. Then come the input arguments, if any. If you don't have any input arguments,
then parentheses are optional. Otherwise, a comma separated list of input
argument names goes between parentheses. Okay, that's the formal description
of the function declaration, but let's see some examples. You can have zero, one, or
multiple output arguments, and zero, one, or multiple input arguments, and
you can have them in any combination. In fact, here are all nine possibilities,
starting with a case in which there are no output and
no input arguments, in example one. And ending with a case in which there
are multiple output arguments and multiple input arguments, in example nine. And what about function names? First off, the name of the function
should be descriptive. For example, if you write a function
that computes the Fibonacci series, don't call it “F” or “X”. Instead, call it “Fibonacci” or “Fibo”, or
something that suggests its purpose. And stay away from the names
of built-in functions, because that can get very confusing,
very fast. If you see a function called sqrt, for example, you're going to expect it to
return the square root of its argument. And furthermore,
if you name your function s-q-r-t, you won't be able to call the built-in
s-q-r-t. You'll be running yours instead. How do you know whether or not there's a built-in function
with a name that you'd like to use? Use the built-in function named “exist”. The command, help exist, will
help you learn how to use it. [MUSIC] [APPLAUSE]