As a Calculator

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

At the bottom of the terminal there is a command prompt >> followed by an input bar, this is where you enter the commands. After entering a command you press enter and the output will appear above the input bar. You can view the commands you have written in the Command List.

image

The arithmetic operators are:

+ - * / ^(to the power of)

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

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

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

  • sin, cos, tan
  • asin, acos, atan
  • exp, log, log10
     
  • sqrt
  • abs
  • round, floor, ceil
  • rem
  • Trigonometric functions in radians
  • Inverse trigonometric functions
  • Exponential function, natural logarithm, logarithm to
    the base 10
  • Square root
  • Absolute value
  • Round to nearest integer, round down, round up
  • 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. formula
  2. formula
  3. formula
  1. ans = 2.8854
  2. ans = 0.0066932
  3. ans = 1.4819

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

by Malin Christersson under a Creative Commons Attribution-Noncommercial-Share Alike 2.5 Sweden License