Mathematics Made Easy With Minimal Octave
This fifth article in the mathematical journey through open source introduces Octave, a nonprogrammer’s way of doing mathematics.
Octave sounds like a musical note, but in reality it is the name of its author's Chemical Engineering professor, who was known for his ‘back-of-theenvelope calculations'.
All of bench calculator, and more!
All the operations of the bench calculator ( bc) are just a subset of octave. So, there's no point in reinventing the wheel. Whatever operations can be done in bc– arithmetical, logical, relational and conditional–can also be done with equal ease in octave. And like bc, it can be used as a mathematical programming language. So, why did we waste time learning bc? We might as well have come directly to octave. Well, there’s one difference–precision. You can't get that in octave. If you need it, you would have to go back to bc. With octave, let’s start with N-dimensions, or in other words, vectors and matrices.
Getting started
Commands: Typing ' octave' on the shell brings up the octave's interactive shell. Type 'quit' or ‘Control-D’ to exit. The interactive shell starts with a welcome message. As in bc, use the option -q for it not to show. Additionally, use the -f option for it not to pick up any local start-up scripts (if any). So, for our examples, the command would be 'octave -qf' to start octave with an interactive shell.
Prompts and results: The input prompt is typically denoted by ' octave:X>', where X is just a number showing the command count. Valid results are typically shown with '<variable> = ', or 'ans = ' or '=> '. The command count is incremented for the next input. Errors cause error messages to be printed and then octave brings back the input prompt without incrementing the command count. Putting a semicolon (;) at the end of a statement suppresses the result (return value) to be displayed.
Comments could start with # or %. For block comments, #{ ... }# or %{ ... }% can be used. Detailed help on a particular topic can be obtained using 'help <topic>' and the complete documentation can be accessed using 'doc' on the octave shell.
Matrices with a heart
We have already seen matrix creation. They can also be created through multiple lines. Octave continues waiting for
further inputs by just prompting '>'. Check below for how to create the 3x3 magic square matrix, followed by various other interesting operations:
Figure 1 shows the plot window that pops up in response to command # 9 – plot and Figure 2 is the bonus magenta heart of stars (*) from polar coordinates draw command # 10 – polar.
What next?
With a ready-to-go level of introduction to octave, we are all set to explore it the fun way. What fun, you may well ask. That's left to your imagination. And as we move on, you could take up one or more fun challenge(s) and try to solve them using octave.