Chapter 5. Extensions: Write Your Own Octave Functions

In this chapter, you will learn how to write your own Octave functions. This will not only enable you to utilize more of Octave's built-in functionality, it also makes it possible to extend Octave to do pretty much anything you want it to in a highly reusable and modular manner.

After reading this chapter, you will be able to:

  • Write your own Octave functions.
  • Check and validate user inputs to the functions.
  • Write function help text.
  • Define mathematical functions that can be used by Octave to solve different numerical problems.
  • Perform simple debugging of your functions.
  • Vectorize your code.

Your first Octave function

In general, the syntax for a function is:

function [output1, output2, ...] = functionname(input1,input2,...) ...

Get GNU Octave now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.