org-howto/octave/octave-crib.org

1.7 KiB

octave crib

#

#

#

Octave examples

this page gathers some octave examples

start octave

$ octave
octave>

comments

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

directory commands from octave prompt

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

run octave code

octave> run ex4/ex4.m

define function

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

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

Provenance

  • .org source for this page is here: file:octave-crib-src.org
  • git hash:
    git rev-parse HEAD