UP | HOME

octave crib .org source

#+title: octave crib
#
# org-publish options
# H:2   controls section numbering.  
#       number top-level and second-level headings only
# ^:{}  require a_{b} before assuming that b should be subscripted.  
#       without this option a_b will automatically subscript b.
#+options: ^:{} H:2
#
# options used exclusively by emacs
#+startup: showall
#
# options used exclusively by the html exporter
#+language: en
# infojs_opt: view:showall toc:nil ltoc:nil mouse:#ffc0c0 path:/web/ext/org/org-info.js
#+html_head: <link rel="stylesheet" type="text/css" href="/web/css/notebook.css" />
#+html_link_home: ../../../index.html
#+html_link_up: ../../../index.html

* Octave examples
  this page gathers some octave examples

** start octave
   #+begin_example
   $ octave
   octave>
   #+end_example

** comments
   #+begin_example
   octave> x=2 % everything after the % is ignored
   #+end_example

** directory commands from octave prompt
   #+begin_example
   octave> pwd
   ans = /home/roland/proj/coursera/machine-learning-ex4
   #+end_example

   #+begin_example
   octave> ls
   ex4 ex4.pdf
   #+end_example

** run octave code
   #+begin_example
   octave> run ex4/ex4.m
   #+end_example

** define function
   #+begin_example
   octave> function f = f(x)
   f = 3*x^3 + 2;
   endfunction
   #+end_example

   #+begin_example
   octave> f(2)
   ans = 26
   #+end_example

** for-loops
   #+begin_example
   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
   #+end_example
 
   #+begin_example
   fib =
      0   1   1   2   3   5   8  13  21  34  55
   #+end_example

* Provenance
  - ~.org~ source for this page is here: file:octave-crib-src.org
  - git hash: src_sh{git rev-parse HEAD}

Author: Roland Conybeare

Created: 2024-09-08 Sun 18:01

Validate