UP | HOME

octave crib

Table of Contents

1. Octave examples

this page gathers some octave examples

1.1. start octave

$ octave
octave>

1.2. comments

octave> x=2 % everything after the % is ignored

1.3. directory commands from octave prompt

octave> pwd
ans = /home/roland/proj/coursera/machine-learning-ex4
octave> ls
ex4 ex4.pdf

1.4. run octave code

octave> run ex4/ex4.m

1.5. define function

octave> function f = f(x)
f = 3*x^3 + 2;
endfunction
octave> f(2)
ans = 26

1.6. for-loops

octave> fib=ones(1,11);
octave> fib(1)=0;
octave> for i=3:11
octave>   fib(i)=fib(i-1)+fib(i-2);
octave> endfor
octave> fib
fib =
   0   1   1   2   3   5   8  13  21  34  55

2. Provenance

Author: Roland Conybeare

Created: 2024-09-08 Sun 18:01

Validate