Little Octave Manual
- to create row vector
$ b = [ 1 2 3 ];
- to create column vector
$ b = [ 1; 2; 3 ];
- to create matrix
$ m = [ 1 2 3; 4 5 6 ];
- you can index vector with () operator
$ b(2) -> 2
- you can index array with () operator
$ m( 1, 3 )
- vector or matrix index starts from 1, not 0 as C.
- you can get whole row from matrix
$ m( 1, : ) -> 1 2 3
- you can get whole column from matrix
$ m( :, 1 ) -> 1 4
- you can create complex number
$ c = 1 + 2I
- you can not create matrix which has different column elements
- to create one matrix
$ ones( 3, 3 ) -> 3x3 matrix whose all elements are 1
- to create zero matrix
$ zeros( 3, 3 ) -> 3x3 matrix whose all elements are 0
- to create eye matrix
$ eyes( 3, 3 ) -> 3x3 matrix whose diagonal elements are 1
- you can create structure likewise C. The structure is defined below
$ elem.x = 1
$ elem.y = 5
$ elem -> { x=1, y=5 }
$ elem = struct( "x", 1, "y", 5 )
- whos commands returns all defined variables
- size function returns size of parameter
- rows function returns row count of matrix
- columns function returns column count of matrix
- isvector and ismatrix functions are used to check parameter type
- you can define a range with [] operator
$ b = [ -2.0 : 1 : 3.0 ] -> -2.0 -1.0 0.0 1.0 2.0 3.0
- .* operator multiplies matrix element by element.
- .+ operator adds matrix element by element.
- .^ operator calculate power of matrix element by element.
- ' operator gets transpose of matrix.
- A.x = y linear system may be solved with x = inv(A) * y. In Octave,
$ x = A\y -> gives solution set
- A/A = A\A = eye
- if x = 2, then 1/x = 0.5, 1\x = 2
- if there is inverse of a matrix, this matrix is square and its ranks equal row/col.
- rank function returns rank of matrix.
- polyval function solves a polynomial for the parameter
$ p = [ 6 -10 0 2 ] -> 6x^3 - 10x^2 + 0x + 2
$ polyval( p, 1 ) -> 6.1^3 - 10.1^2 + 0.1 + 2 = -2
- rand() function returns a random number between 0 and 1.
- rand( n, m ) function call returns a nxm matrix whose all elements are random numbers between 0 and 1.
- min and max functions return min and max value of each column of a matrix.
- sort function sorts each column of a matrix.
- find function returns non-zero elements of a matrix
$ find( A )
$ find( A < 0.5 ) -> returns value which are smaller than 0.5
- any returns 1 for each column of matrix whether the column has any non-zero value
- all returns 1 for each column of matrix whether the all value of column are non-zero values
- round, floor, ceil and fix functions are used to convert floating number to integer.
- sum function adds all elements of a matrix.
- prod function multiplies all elements of a matrix.
- cumsum and cumprod perform same operations with accumulation.
- det function returns determinant of a matrix.
- eig function returns eigen values and vectors of matrix.
$ [V, L] = eig( A )
- orth(A) -> orthonormal range space
- null(A) -> orthonormal null space
- inv(A) or inverse(A) -> inverse of the matrix
- roots function returns roots of a polynomial.
- polyint returns integral of a polynomial, polyder returns derivation of a polynomial.
- plot draws a graphics with two parameters.
- set(gca, <param>, <value>) edits current plot
$ set(gca, "linewidth", 2 ) -> make linewidth of graphic 2
$ set(gca, "xlim", [-10 10] ) -> make range of X axes [-10 10]
$ set(gca, "ylim", [-10 10] ) -> make range of Y axes [-10 10]
$ set(gca, "fontsize", 10) -> make fontsize 10
$ set(gca, "xlabel", "x" ) -> make xlabel x
$ set(gca, "ylabel", "f(x)" ) -> make ylabel f(x)
$ set(gca, "title", "My first plot" ) -> add title upper side of graphic
- plot( x, f, "o", "markersize", 4, "color", "red" ) draws graphics with marker o and color red.
- line function draw line on graphics
$ line( [-2 2], [-5 5], "linewidth", 1 ) -> draws line from (-2,2) to (-5,5), linewidth is 1
- text function writes text on graphics
$ text( -2, 2, "root", "fontsize", 10 ) -> prints 'root' on (-2,2) point
- legend("f(x)") add f(x) string right upper of graphic screen.
- fplot("sin", [0 2*pi], 50) -> draws plot, it is alternative to plot for math fn
- clf function clear figure
- subplot function divides parts to figure.
$ subplot(2, 3, 1) -> part screen 2 row and 3 column, then draw figure on 1
$ subplot(2, 3, 3) -> part screen 2 row and 3 column, then draw figure on 3
- print( "my_plot.png", "-dpng" ) -> save current plot with png extension in octave workspace directory
- other save format is eps, pdf, ps, gif, jpg/jpeg, tex, pstex ...
- to draw 3D surface
$ x = [-2:0.1:2];
$ y = x;
$ [X Y] = meshgrid(x, y);
$ Z = X.^2 - Y.^2;
$ surface( X, Y, Z );
- view( azim, elev ) -> change view point of surface
- colormap( "summer" ) -> change surface color distribution ( winter, copper, autumn, pink ... )
- contour3( X, Y, Z ) -> diplays contour plots of surface
$ b = [ 1 2 3 ];
- to create column vector
$ b = [ 1; 2; 3 ];
- to create matrix
$ m = [ 1 2 3; 4 5 6 ];
- you can index vector with () operator
$ b(2) -> 2
- you can index array with () operator
$ m( 1, 3 )
- vector or matrix index starts from 1, not 0 as C.
- you can get whole row from matrix
$ m( 1, : ) -> 1 2 3
- you can get whole column from matrix
$ m( :, 1 ) -> 1 4
- you can create complex number
$ c = 1 + 2I
- you can not create matrix which has different column elements
- to create one matrix
$ ones( 3, 3 ) -> 3x3 matrix whose all elements are 1
- to create zero matrix
$ zeros( 3, 3 ) -> 3x3 matrix whose all elements are 0
- to create eye matrix
$ eyes( 3, 3 ) -> 3x3 matrix whose diagonal elements are 1
- you can create structure likewise C. The structure is defined below
$ elem.x = 1
$ elem.y = 5
$ elem -> { x=1, y=5 }
$ elem = struct( "x", 1, "y", 5 )
- whos commands returns all defined variables
- size function returns size of parameter
- rows function returns row count of matrix
- columns function returns column count of matrix
- isvector and ismatrix functions are used to check parameter type
- you can define a range with [] operator
$ b = [ -2.0 : 1 : 3.0 ] -> -2.0 -1.0 0.0 1.0 2.0 3.0
- .* operator multiplies matrix element by element.
- .+ operator adds matrix element by element.
- .^ operator calculate power of matrix element by element.
- ' operator gets transpose of matrix.
- A.x = y linear system may be solved with x = inv(A) * y. In Octave,
$ x = A\y -> gives solution set
- A/A = A\A = eye
- if x = 2, then 1/x = 0.5, 1\x = 2
- if there is inverse of a matrix, this matrix is square and its ranks equal row/col.
- rank function returns rank of matrix.
- polyval function solves a polynomial for the parameter
$ p = [ 6 -10 0 2 ] -> 6x^3 - 10x^2 + 0x + 2
$ polyval( p, 1 ) -> 6.1^3 - 10.1^2 + 0.1 + 2 = -2
- rand() function returns a random number between 0 and 1.
- rand( n, m ) function call returns a nxm matrix whose all elements are random numbers between 0 and 1.
- min and max functions return min and max value of each column of a matrix.
- sort function sorts each column of a matrix.
- find function returns non-zero elements of a matrix
$ find( A )
$ find( A < 0.5 ) -> returns value which are smaller than 0.5
- any returns 1 for each column of matrix whether the column has any non-zero value
- all returns 1 for each column of matrix whether the all value of column are non-zero values
- round, floor, ceil and fix functions are used to convert floating number to integer.
- sum function adds all elements of a matrix.
- prod function multiplies all elements of a matrix.
- cumsum and cumprod perform same operations with accumulation.
- det function returns determinant of a matrix.
- eig function returns eigen values and vectors of matrix.
$ [V, L] = eig( A )
- orth(A) -> orthonormal range space
- null(A) -> orthonormal null space
- inv(A) or inverse(A) -> inverse of the matrix
- roots function returns roots of a polynomial.
- polyint returns integral of a polynomial, polyder returns derivation of a polynomial.
- plot draws a graphics with two parameters.
- set(gca, <param>, <value>) edits current plot
$ set(gca, "linewidth", 2 ) -> make linewidth of graphic 2
$ set(gca, "xlim", [-10 10] ) -> make range of X axes [-10 10]
$ set(gca, "ylim", [-10 10] ) -> make range of Y axes [-10 10]
$ set(gca, "fontsize", 10) -> make fontsize 10
$ set(gca, "xlabel", "x" ) -> make xlabel x
$ set(gca, "ylabel", "f(x)" ) -> make ylabel f(x)
$ set(gca, "title", "My first plot" ) -> add title upper side of graphic
- plot( x, f, "o", "markersize", 4, "color", "red" ) draws graphics with marker o and color red.
- line function draw line on graphics
$ line( [-2 2], [-5 5], "linewidth", 1 ) -> draws line from (-2,2) to (-5,5), linewidth is 1
- text function writes text on graphics
$ text( -2, 2, "root", "fontsize", 10 ) -> prints 'root' on (-2,2) point
- legend("f(x)") add f(x) string right upper of graphic screen.
- fplot("sin", [0 2*pi], 50) -> draws plot, it is alternative to plot for math fn
- clf function clear figure
- subplot function divides parts to figure.
$ subplot(2, 3, 1) -> part screen 2 row and 3 column, then draw figure on 1
$ subplot(2, 3, 3) -> part screen 2 row and 3 column, then draw figure on 3
- print( "my_plot.png", "-dpng" ) -> save current plot with png extension in octave workspace directory
- other save format is eps, pdf, ps, gif, jpg/jpeg, tex, pstex ...
- to draw 3D surface
$ x = [-2:0.1:2];
$ y = x;
$ [X Y] = meshgrid(x, y);
$ Z = X.^2 - Y.^2;
$ surface( X, Y, Z );
- view( azim, elev ) -> change view point of surface
- colormap( "summer" ) -> change surface color distribution ( winter, copper, autumn, pink ... )
- contour3( X, Y, Z ) -> diplays contour plots of surface