# NIUHE

## Functions

To create a function, type the function code in a text editor (e.g. gedit or notepad), and save the file as "functionName.m"

Example function:

To call the function in Octave, do either:

1. Navigate to the directory of the functionName.m file and call the function:

2. Add the directory of the function to the load path and save it:

Octave's functions can return more than one value:

Call the above function this way:

## Vectorization

Vectorization is the process of taking code that relies on loops and converting it into matrix operations. It is more efficient, more elegant, and more concise.

As an example, let's compute our prediction from a hypothesis. Theta is the vector of fields for the hypothesis and x is a vector of variables.

With loops:

With vectorization:

If you recall the definition multiplying vectors, you'll see that this one operation does the element-wise multiplication and overall sum in a very concise notation.