# Octave: A Free, High-Level Language for Mathematics

For numerical computing, high level languages offer advantages over more traditional languages, such as FORTRAN or C. Built-in graphics capabilities, automatic variable typing and flexible data structures combine to provide an environment in which it is easy to develop your ideas without having to fight with the language. That's not to say that FORTRAN and C are of no use, just that sometimes you want to make life a bit easier.

Matlab is a one such language. It is available on many platforms (including Linux) and provides powerful facilities for manipulating matrices, as well as other numerical functions. Unfortunately, Matlab is commercial software and wasn't available for Linux until recently (in the last twelve months or so). However, there are other, freely-available alternatives, and Octave is one such alternative.

Superficially, Octave looks very much like Matlab, and the
description in its LSM entry reads “GNU Matlab—A numerical matrix
mathematics program.” To begin, type **octave** at
the shell prompt, and Octave greets you with its own prompt. Now we
can start doing math.

As you might expect, entering and manipulating matrices is
one of Octave's strengths. (In order to differentiate Octave
commands from the output, the prompt
**octave:number of the
command** precedes the commands in the
examples below.) We can enter a matrix with the command:

octave:1 a=[1 2 ; 3 4]

Octave then reports the result of the command, namely:

a = 1 2 3 4To suppress output, simply place a semicolon after the command. Note that we didn't have to worry about declaring the size or type of the matrix

**a**, we just type it in and start working with it. For example, we can get the transpose of

**a**by typing:

octave:2 a' ans = 1 3 2 4Arithmetic operators such as

**+**,

**-**and

*****act as matrix operators unless they are preceded by a period, in which case they act in an element by element sense. Octave also provides the forward and backward slash operators that perform matrix right and left division. Again, these can be used in an element-wise fashion. So, given another matrix:

octave:3 b=[1 0; 3 2] b = 1 0 3 2we can find the matrix product of

**a**and

**b**with the command:

octave:4 a*b ans = 7 4 15 8Or define the (

**i,j**)th entry of the product is the product of the (

**i,j**) entries in

**a**and

**b**with the command:

octave:5 a.*b ans = 1 0 9 8Matrix elements can easily be selected by index, so to get the (1,1) entry of

**a**, type:

octave:6 a(1,1) ans=1We can select a row or column using the colon operator, exactly as in Matlab. Thus, to select the first column of

**a**type the command:

octave:7 a(:,1) ans = 1 3And to select the first row of

**a**type:

octave:8 a(1,:) ans = 1 2As well as these elementary operations, Octave provides functions that perform higher-level operations, such as finding the eigenvalues of a matrix, by using a command like the following:

octave:9 eig(a) ans = 5.37228 -0.37228Alternatively, you can find the eigenvalues and eigenvectors by giving the following command:

octave:10 [v,d]=eig(a) v = 0.41597 -0.82456 0.90938 0.56577 d = 5.37228 0.00000 0.00000 -0.37228This is a demonstration of one of the main advantages of using a high level language like Octave. Writing a FORTRAN or C program to find the eigenvalues of a matrix would take a lot more time and effort than it does in Octave. Moreover, Octave routines are usually based on well-known, high quality algorithms, so you can have faith in the results.

Octave provides many other matrix routines, which are detailed in the manual and in the on-line help system.

Octave also lets the user define his own functions via the
**function** keyword. A function definition looks
like this:

function [output values] = name (input values) sequence of commands endfunction

The input and output values are optional, so it is possible to write a function that takes no arguments and returns no values, such as

octave:11 function hello printf("hello\n") endfunctionThe

**printf**statement prints the quoted string to the screen, and the \n is interpreted as a newline. Invoke the function by typing its name:

octave:12 hello helloObviously, functions that don't take arguments or return values aren't all that useful. To accept arguments, list them after the function name in the following manner:

octave:13 function add(x,y) x+y endfunction octave:14 add(1,2) ans = 3The output came from the statement

**x+y**--if we had ended the line with a semicolon, there wouldn't have been any output from the

**add**command. To assign the output to a variable, define the function in this way:

octave:15 function sum=add(x,y) sum=x+y; endfunctionNow, if we type

**add(1,2)**, we get exactly the same result as before. However, by defining an output variable, we can assign the result of the

**add**function to a variable in this way:

octave:16 fred=add(1,2) fred=3A very powerful feature of Octave is the ability to return multiple values from a function. This feature exists in Matlab, but not in FORTRAN. For example, the following function:

octave:17 function [sum,diff]=sumdiff(x,y) sum=x+y; diff=x-y; endfunctionreturns multiple values when invoked as:

octave:18 ns,d]=sumdiff(1,2) s = 3 d = -1Functions can be defined at the keyboard, as we did in these examples, or stored in a file and used again. This lets you build a suite of routines for whatever tasks you want. All you have to do is put the files (identified with a

**.m**suffix) somewhere where Octave can find them. The built-in variable

**LOADPATH**specifies where Octave should look for the

**.m**files. Many of Octave's standard functions are defined in

**.m**files. You can also access user-supplied C++ routines within Octave, although this feature is not yet fully developed.

Octave also provides a full programming language, with flow control and looping constructs, as well as extensive input-output facilities. It is possible to write quite sophisticated programs in Octave, and development time is considerably shorter than you would expect using FORTRAN or C.

## Trending Topics

## Webinar

### Practical Task Scheduling Deployment

On Demand

One of the best things about the UNIX environment (aside from being stable and efficient) is the vast array of software tools available to help you do your job. Traditionally, a UNIX tool does only one thing, but does that one thing very well. For example, grep is very easy to use and can search vast amounts of data quickly. The find tool can find a particular file or files based on all kinds of criteria. It's pretty easy to string these tools together to build even more powerful tools, such as a tool that finds all of the .log files in the /home directory and searches each one for a particular entry. This erector-set mentality allows UNIX system administrators to seem to always have the right tool for the job.

Cron traditionally has been considered another such a tool for job scheduling, but is it enough? This webinar considers that very question. The first part builds on a previous Geek Guide, Beyond Cron, and briefly describes how to know when it might be time to consider upgrading your job scheduling infrastructure. The second part presents an actual planning and implementation framework.

Join *Linux Journal*'s Mike Diehl and Pat Cameron of Help Systems.

Free to *Linux Journal* readers.

The Firebird Project's Firebird Relational Database | Jul 29, 2016 |

Stunnel Security for Oracle | Jul 28, 2016 |

SUSE LLC's SUSE Manager | Jul 21, 2016 |

My +1 Sword of Productivity | Jul 20, 2016 |

Non-Linux FOSS: Caffeine! | Jul 19, 2016 |

Murat Yener and Onur Dundar's Expert Android Studio (Wrox) | Jul 18, 2016 |

- The Firebird Project's Firebird Relational Database
- Stunnel Security for Oracle
- My +1 Sword of Productivity
- Non-Linux FOSS: Caffeine!
- Managing Linux Using Puppet
- SUSE LLC's SUSE Manager
- Murat Yener and Onur Dundar's Expert Android Studio (Wrox)
- Doing for User Space What We Did for Kernel Space
- SuperTuxKart 0.9.2 Released
- Google's SwiftShader Released

## Geek Guides

With all the industry talk about the benefits of Linux on Power and all the performance advantages offered by its open architecture, you may be considering a move in that direction. If you are thinking about analytics, big data and cloud computing, you would be right to evaluate Power. The idea of using commodity x86 hardware and replacing it every three years is an outdated cost model. It doesn’t consider the total cost of ownership, and it doesn’t consider the advantage of real processing power, high-availability and multithreading like a demon.

This ebook takes a look at some of the practical applications of the Linux on Power platform and ways you might bring all the performance power of this open architecture to bear for your organization. There are no smoke and mirrors here—just hard, cold, empirical evidence provided by independent sources. I also consider some innovative ways Linux on Power will be used in the future.

Get the Guide
## Comments

## nice thoughts

Well, the post is actually the freshest topic on this registry related issue. jasmin live I fit in with your conclusions and will thirstily look forward to your coming updates. Just saying thanks will not just be sufficient, for the phenomenal lucidity in your writing.cameraboys.com I will right away grab your rss feed to stay abreast of any updates.

## I wish our university used

I wish our university used this as well as I have become used to it. The interface on Octave is a lot easier to use in my opinion. Matlab will just have to do sometimes though. college grants for students

## Matlab or octave

Where else could anyone get that kind of info written in such a perfect way?

Matlab or octave

best regards

## my answer

the best part of octave is it can parse matlab code , so it's very useful for students like me .however, matlab can not parse octave code .

another thing,you can type single quotes and double quotes in octave which like we know that's impossible with matlab(accept only singles quotes).

these are two big difference for me so I choose Octave over Matlab .

Orthopaedic Shoe Repairs

## Thank you for taking the

Thank you for taking the chance to deliver this affair. I’m pleased I discovered your site on this material. I’m doing research on this interest right now and this was great. Keep up the great work.I’m doing research on this interest right now and this was great. Keep up the great work !!!!!!!!

koyun oyunları

## @windows version

Octave can be used on windows using cygwin.

## Very nice site. Spray

Very nice site.

Spray Insulation

## Didn't know that

Didn't know you could use it with windows. I'll check cygwin further. Thanks. S.T. repossessed cars insider tips

repossessed cars basics

## Great article. It's hard to

Great article. It's hard to say which one is the best.

## Re: Octave: A Free, High-Level Language for Mathematics

Nice explanation, thanks. Business Marketing

## Fortran is my first programming language

When I was young, Fortran is my first programming language. Then I learned Matlab and Octave.. but I think Matlab is easier than Octave. thanks, Pampers Diapers

## disagree

Have to disagree Octave is far more intuitive. curtains and blinds

## Have used both, Octave and

Have used both, Octave and Matlab, but i prefer the latter, though i don't use matrixes that often. online

sex camlive chat## Thanks to your article, you

Thanks to your article, you don't know me and I live way too far away...

Why yes you can. m files work just fine with octave.

Übersetzung Spanisch Deutsch

Übersetzer Übersetzer Engisch Deutsch

## Matlab's return is promising

Matlab's return is promising it will help in Computer Aided Designing

Devs

## There is difference between

There is difference between Matlab and Octave. Octave is open source whereas Matlab is proprietary. Matlab surly is more comfortable working whereas Octave is free, that's why I love to work with Octave.

Sam

## user friendly

which one that give you more user friendly experience?

how to get pregnant

## Doesn't this cause a conflict?

Great article but one quick question...?

"The input an' output values be optional, so it is possible t' write a function that takes no arguments an' returns no values, such as

octave:11 function hello

printf("hello\n")

endfunction"

How does this not result in conflict when compiling?

Mediation Jobs

## What is my Love?

My heart is my love

My love is my family

My family is my future

My future is my destiny

My destiny is my ambition

My ambition is my inspiration

My inspiration is my motivation

My motivation is my belief

My belief is my peace

My peace is my target

My target is heaven

My heaven is my home

My home is my eternity

My eternity is my judgment from my creator

If Tomorrow Never Comes

If I knew it would be the last time that I see you walking out of the door, I would have given you a hug and kiss and even call you back for one more.

If I knew it would be the last time I will hear your voice, I would have video taped each action and word of yours, so I could play them back day after day.

If I knew it would be the last time we would meet, I could have spared an extra minute or two to stop and say "I love you,"

If I knew it would be the last time I would be there to share your day, I could not have allowed this to slip away.

For surely there's always tomorrow to make up for an oversight, and we always get a second chance to make everything right.

The more we are still on earth living there will be always tomorrow

Send Free Texts

Send Free Texts to say good morning, good afternoon, good night, and toy I LOVE YOU

Send Free Texts Gtalk Unlimited India Calling

## Octave: A Free, High-Level Language for Mathematics

Yeah, I wish we had this too in our university. I imagine calculating mathematical equations in just pressing some keys in the keyboard and not solving those problems with very long solutions by hands.

computer repairs in new york

## Octave: A Free, High-Level Language for Mathematics

Nice article.

## First time I heard about this

Thanks for the information octave I heard about this first time and I don have much knowledge about it, now you article has given me all the details to understand the basics about it will learn more thanks.

## ???????? ?????: ???????? ???

???????? ?????: ???????? ??? ???? ? ????????? ???????? ?? ? ???? ???????: ??? ????? ???? ????? ???? ??????? ?????????.

play blackjack safe online casino online bonus slots

## thank you

thnaks for shared ßß Our website is: http://www.cilekerotik.com

## Wow...

Wow!I am pretty new to learn about this but would like to know which one in the end is the way to go?Is it Matlab or octave?I've read that Matlab can be more powerful, is that correct?

Musikproduzent im Tonstudio

## I have been learning computer

I have been learning computer languages but never even heard about Octave. May be because it is old now and isnt used much but it is always interesting to know more. I will be digging in deep to find more information on this. electric meat slicer

## That's all we need :)

That's all we need, another high-level Maths language. I find C difficult enough to deal with. My Dad was right, should have done law rather than engineering :)

## which one?

So in the end which one is the way to go? Matlab or octave? Both have benefits

Hearing Loss Treatment

## I agree with David

I totally agree with David that it's almost mandatory that you also install the octave-forge package...

Backlink Software

## Octave is great

"I'd say there's a *big* difference between Matlab and Octave. Octave is Open Source, that means it's free as opposed to Matlab which you have to pay for. Very powerful."

Absolutely agree with this. I love Matlab but the flexibility that I have with Octave is awesome.

article submission service

## Octave VS Matlab - Big Difference

I'd say there's a *big* difference between Matlab and Octave. Octave is Open Source, that means it's free as opposed to Matlab which you have to pay for. Very powerful.

## Coding Style

I see about the Visual Basic notation like if .. else .. end, but Octave, like Matlab uses C oriented notations also, for example a ! in Octave is a NOT, as it is in C, instead of <> in VB. Also you can use all the C based = symbols like: `+=', `-=', `*=', `/=', `^=', `.*=', `./=', and `.^='.

## Octave Origins

From what I'm getting, James B. Rawlings and John W. Eaton at the University of Texas were the first to start development of Octave, clear back in 1988. In '92 James Rawlings started development full time. How does open source software put food on the table. I'm still puzzled.

## Almost VB Style

This is my first introduction to either Matlab or Octave. The format almost has a Visual Basic feel to it; not like C at all. Then again, maybe just the function definitions. For me, the advantage would be to do server side math, thereby not relying on flaky client side Javascript, which is anything but precision.

## Octave is no doubt an equally

Octave is no doubt an equally impressive piece of software and just as functional as Matlab. I've used both and have no preference either way as they both work in very similar manners. There is no doubt that Octave is a great alternative to Matlab and gets the job done just as well. backpacking Europe

## Newest Octave Release

As of August 1, 2010 the newest version 3.3.52 is available in BETA for people interested in helping test. Be sure to download it and give it a spin: Octave Downloads.

## Windows Version

MatLab is indeed a great high level program (language?) for doing precision math. It's available for Windows or Linux. I didn't see if Octave is also available for both.

## mathlab is still better

I have used both programs and I think mathlab is still much than octave.

adjustable dumbbells

## I am starting to learn about

I am starting to learn about this but would like to know that this will be used for quite some time down the road. I see this is dated 1997, has there been any changes to this, or is there any news of switching to a different system? custom t-shirts

## Changes

I see this is dated 1997, has there been any changes to this, or is there any news of switching to a different system? I am starting to learn about this but would like to know that this will be used for quite some time down the road. Outdoor Pool Furniture

## I admire the valuable

I admire the valuable information you offer in your articles. I will bookmark your blog and have my children check up here often. I am quite sure they will learn lots of new stuff here than anybody else! Colorado Personal Injury

## You don't know me and I live

You don't know me and I live way too far away... but my name is Peter. I'm doing an undergrad I.T. degree and this semester I'm doing a subject on Pattern Recognition (eventually using Neural Networks). The subject demands use of Matlab and for some reason, our I.T. faculty seems to be fairly poor at supporting anything Linux (except for network admin and programming based subjects). iphone headphones

## Matlab OR Octave

the best part of octave is it can parse matlab code , so it's very useful for students like me .however, matlab can not parse octave code .

another thing,you can type single quotes and double quotes in octave which like we know that's impossible with matlab(accept only singles quotes).

these are two big difference for me so I choose Octave over Matlab .

router wireless reviews

## I tried Octave

I tried Octave once , it's unbelievable .

very very useful for people who use Matrix (resolve Jordan and Gauss problem easily)

## I wish our university had

I wish our university had Octave installed. But most machines in Ottawa are Windows.

## I wish we had it too

Yeah, I wish we had this too in our university. I imagine calculating mathematical equations in just pressing some keys in the keyboard and not solving those problems with very long solutions by hands.

Rikki

Link Building Service

## Great

Thank you for such a fantastic blog. Where else could anyone get that kind of info written in such a perfect way? I have a presentation that I am presently working on, and I have been on the look out for such information. Local Marketing

## You have a lot of resources

You have many resources on this page.

I always consult linuxjournal so many things about my job, and my school.

If you need more info, send me an email.

Betito

Link Building Service

## What I like!

I like how it provides a convenient command line interface for solving linear and nonlinear problems numerically! Also great features are: Matrices as fundamental data type and Built-in support for complex numbers.

## Thank you!

I used Matlab exclusively in my MSc. never knew that there was a Gnu'able version. Installed from my GNU/Linux's distrobution and taking it for a spin. Thanks :-)

jayeola