Octave functions
You can think of an Octave function as a kind of general mathematical function—it takes inputs, does something with them and returns outputs. For example, in Command 20 in Chapter 2, we used Octave's real
function. We gave it the complex scalar input variable z
and it returned the real part of z
.
Octave functions can in general take multiple inputs (also called arguments or input arguments) and return multiple outputs. The general syntax for a function is:
[output 1, output 2, ...] = function name(input 1, input 2, ...)
The inputs to and the outputs from a function can be scalars, multidimensional arrays, structures, and so on. Note that the outputs need not to be separated with commas. Since Octave does not operate with type specifiers, the functions must be able to deal with all kind of inputs, either by performing the operations differently (and thereby likely also to return different outputs), or by reporting an error. Sometimes we will use function interface instead...