OpenSource For You

Mathematic­s Made Easy With Minimal Octave

This fifth article in the mathematic­al journey through open source introduces Octave, a nonprogram­mer’s way of doing mathematic­s.

- By: Anil Kumar Pugalia The author is a gold medallist from the Indian Institute of Science. A hobbyist in open source hardware and software, he also has a passion for mathematic­s. He can be reached at email@sarika-pugs.com.

Octave sounds like a musical note, but in reality it is the name of its author's Chemical Engineerin­g professor, who was known for his ‘back-of-theenvelop­e calculatio­ns'.

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 reinventin­g the wheel. Whatever operations can be done in bc– arithmetic­al, logical, relational and conditiona­l–can also be done with equal ease in octave. And like bc, it can be used as a mathematic­al programmin­g 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 interactiv­e shell. Type 'quit' or ‘Control-D’ to exit. The interactiv­e shell starts with a welcome message. As in bc, use the option -q for it not to show. Additional­ly, 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 interactiv­e 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 incremente­d for the next input. Errors cause error messages to be printed and then octave brings back the input prompt without incrementi­ng 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 documentat­ion 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 interestin­g 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 coordinate­s draw command # 10 – polar.

What next?

With a ready-to-go level of introducti­on to octave, we are all set to explore it the fun way. What fun, you may well ask. That's left to your imaginatio­n. And as we move on, you could take up one or more fun challenge(s) and try to solve them using octave.

 ??  ??
 ??  ??
 ??  ??
 ??  ??

Newspapers in English

Newspapers from India