Octave Example 1: Getting Started

Al Fischer

First Approximation: Octave is a calculator

In a basic sense, the Jupyter interface is just a glorified calculator.


In [21]:
### add 2 + 3

2 + 3


ans =  5

In [23]:
### divide

3 / 4


ans =  0.75000

In [26]:
### natural log

log(10)
log10(10)


ans =  2.3026
ans =  1

In [30]:
### what about trig?

cos(pi)
sin(pi/2)


ans = -1
ans =  1

PAUSE: Find the sine of 45 degrees

Matrix Math


In [50]:
a = [1 2 3 4];

In [51]:
a


a =

   1   2   3   4


In [52]:
a + 2


ans =

   3   4   5   6


In [54]:
B = [1 2 3 4; 6 8 10 12]


B =

    1    2    3    4
    6    8   10   12


In [55]:
C = B / 2


C =

   0.50000   1.00000   1.50000   2.00000
   3.00000   4.00000   5.00000   6.00000


In [56]:
a * B


error: operator *: nonconformant arguments (op1 is 1x4, op2 is 2x4)

In [57]:
a .* B


ans =

    1    4    9   16
    6   16   30   48


In [58]:
D = a .* B


D =

    1    4    9   16
    6   16   30   48


In [62]:
D(1, 4)


ans =  16

In [43]:
x = [0:0.1:4*pi];
y = [sin(x); cos(x)];

plot(x, y);
xlabel ("x");
ylabel ("y");
legend("sin(x)", "cos(x)")