All published worksheets from http://sagenb.org
Image: ubuntu2004
Using Octave as simple Calculator
Using arrays:
Defining an array:
using the ":" operator
vectors can be added:
vectors can be multiplied/diviede by scalars:
We can do elementwise operations with help of "." :
Matrices
Everything is a Matrix....
Defining a Matrix is quite the same as with vectors:
There are several other ways to build a Matrix:
A Matrix can also build as vector of vectors:
We can multiply a matrix with another matrix:
or with a vector:
but we have to be careful with dimensions!
use ' for adjoint and .' for transpose:
Programming
Comparisons
the if statement
for loop:
while:
defining of functions
examples:
Let's do more complicated ones:
Remark: The ++ Statement above is something, which differs octave from matlab. In matlab you would have to write y = y+1
Octave also supports the +=, -=, *=, /= statements
Another important difference: In Matlab every loop or function is closed with "end", in octave you can use end also, but the provided endif, endwhile, endfor etc. statements make the code more readible!
Of course octave has also disadvanteges, especially matlab has more features like simulink included!
To call a function in octave/matlab save it to an *.m file with the name of the function. If you start octave in the folder you can call the function just with it's name.
Another thing: Matlab has it's own nice interface. But for octave there are also some nice interfaces like QOctave which is written in Qt, or the good old emacs also supports octave.