# Get started with Octave

There are a number of Open Source alternatives to the program MatLab, one of the most known alternatives is GNU Octave. When using Octave you use a command line to enter commands. Octave can be downloaded and installed from GNU Octave.

### Install on Mac

If using Mac:

Install Homebrew.

Install XCode from App Store.

Open and run the XCode app to agree to the License Agreement.

Install XQuartz.

Import science packages, open the terminal and enter:

brew tap homebrew/science


Install Octave (this takes time):

brew update && brew upgrade
brew install gcc
brew install octave --without-docs


Update:

brew update && brew upgrade


At the end of the process a summary is shown displaying the path to Octave. If following is shown:

Summary
/usr/local/Cellar/octave/3.8.1


then the path to Octave is /usr/local/Cellar/octave/3.8.1/bin/Octave Open AppleScript Editor and make a New Document. Write following:

tell application "Terminal"
do script "/path/to/octave; exit"
end tell


where /path/to/octave is the path. Save the script as Octave.app, select Application when saving.

## As a calculator

The easiest way to get started, is to use Octave as a calculator.

The arithmetic operators are:

+ - * / ^(to the power of)

There are predefined constants in Octave, some of them are listed below:

constant explanation
pi , e , i Make a wild guess!
Inf (infinity) Operations yielding numbers larger than the maximum
floating point will give this answer.
NaN (not a number) Operations that can not be defined in any reasonably

There are also a number of predefined mathematical functions in Octave, some of them are listed below:

function explanation
sin, cos, tan Trigonometric functions using radians
asin, acos, atan Inverse trigonometric functions
exp, log, log10 Exponential function, natural logarithm, logarithm to
the base 10
sqrt Square root
abs Absolute value
round, floor, ceil Round to nearest integer, round down, round up
rem Remainder when doing integer division

### Showing more decimals

You can show more decimals by typing format long. Go back to showing few decimals by typing format short.

## Exercise 1

Calculate following expressions

1. $$\sqrt[5]{200}$$
2. $$\dfrac{3\cdot 10^{-3}}{0.001+\sqrt{0.2}}$$

3. $$\dfrac{2^{3+\sin{0.3}}+5}{10}$$

1. ans = 2.8854
2. ans = 0.0066932
3. ans = 1.4819

You can see old commands by using up/down arrow keys.

## Exercise 2

Guess the output of following commands, then check the answers given by Octave

1. 1/0 0/0 tan(pi/2)
2. inf+inf inf-inf inf/inf inf*inf
3. nan+2 nan+nan

## Exit Octave

Exit Octave by writing exit or quit.