% Author: Micha³ Bernardelli
% 2014.09.29
% Introduction to Octave: 
%   operations with matrices

% copy the code to the window at http://lavica.fesb.hr/octave/octave-on-line_en.php

    % matrix
A = [1 2 3 4
5 6 7 8
-4 3 0 1
2 0 -3 4]
fprintf("Dimenstion of A: %dx%d\n", size(A));
fprintf("Transposition of A:\n");
disp(A');
fprintf("Determinant of A: %f\n", det(A));
fprintf("Inverse matrix to A:\n");
B = A^-1;
disp(B);
fprintf("Check A*A^-1:\n");
disp(A*B);
fprintf("Multiplication (power) of matrices: A^3\n");
disp(A^3);
fprintf("Diagonal of A:\n");
diag(A)
fprintf("Diagonal above the diagonal of A:\n");
diag(A,1)
fprintf("Diagonal below the diagonal of A:\n");
diag(A,-1)
fprintf("Zero matrix\n");
disp(zeros(2,3))
fprintf("Matrix of ones\n");
disp(ones(4,3))
fprintf("Identity matrix\n");
disp(eye(5))
fprintf("Diagonal matrix\n");
C = eye(5)*10
fprintf("Another diagonal matrix\n");
C = eye(5);
C(2,2) = 2;
C(3,3) = 3;
C(4,4) = 4;
C(5,5) = 5;
C
fprintf("Another way to get the same diagonal matrix\n");
diag(1:5)
