% Octave and Matlab ignore anything that comes after a % percent sign. Text after percent signs are % comments intended for you, the human. % % Here are six snippets which you can cut and paste into % the online Octave utility. %%%%%%%%%%%%% SNIPPET 1 %%%%%%%%%%%%%%%%%%%%% % The following enters a matrix and stores it in the % variable A A=[1, 2, 3; % You could also type all this on one line -1, 2, 2; % but like this it's easier to see what 1, 0, 1] % you typed % You can now compute the inverse and determinant of A inv(A) det(A) % DIY: % See what happens if you replace A above with a % non invertible matrix like % A = [1, 1; 2, 2] %%%%%%%%%%%%% SNIPPET 2 %%%%%%%%%%%%%%%%%%%%% % Start with our matrix A again % and multiply it with itself a few times A=[1, 2, 3; -1, 2, 2; 1, 0, 1] B=A*A A*A*A*A B*B % DIY : See what you get when you compute A*inv(A) %%%%%%%%%%%%% SNIPPET 3 %%%%%%%%%%%%%%%%%%%%% % Start with our matrix A again A=[1, 2, 3; -1, 2, 2; 1, 0, 1] % The following command gives you the % characteristic polynomial of A, i.e. % det(A - lambda I) p = poly(A) % The output is stored in the variable 'p'. To % print this output as a polynomial instead of % just the coefficients do this: polyout(p, "X") %%%%%%%%%%%%% SNIPPET 4 %%%%%%%%%%%%%%%%%%%%% % The command 'roots' finds the roots of a polynomial, % real and complex. p = [1 3 1 3] polyout(p, "X") roots(p) %%%%%%%%%%%%% SNIPPET 5 %%%%%%%%%%%%%%%%%%%%% % Start with our matrix A again A=[1, 2, 3; -1, 2, 2; 1, 0, 1] p = poly(A) roots(p) % These are the eigenvlaues of A ! %%%%%%%%%%%%% SNIPPET 6 %%%%%%%%%%%%%%%%%%%%% % Start with our matrix A again A=[1, 2, 3; -1, 2, 2; 1, 0, 1] % there's a shortcut to getting the eigenvalues, % namely eig(A) % The following also gives you the eigenvectors % of A. The eigenvectors are stored in V and % the matrix D is a diagonal matrix with the % eigenvalues of A on the diagonal. [V D] = eig(A)