%%% matrices.m: to run this script noninteractively, type %%% matlab < manipul.m > manipul.out %%% %%% will dump output into file manipul.out %%% %%% contains some examples of array and matrix manipulation %% Cleanup the environment a bit clear variables; clc; echo on x = [1.0 2 3.0] A = [4.0 5.0 7.0; 8.1 6.2 1.2] A = [A ; x] %% Inverse of A inv(A) %% Transpose of matrix B = A' %% Sum of matrices C = A + B %% Matrix Products C = A*B y = C*x' %% Matrix Factorining [L U] = lu(A) [Q R] = qr(A) %% Eigenvalues computed two different ways %% Poly uses an unusual algorithm - see the reference manual eig(A) roots(poly(A)) %% V = Eigenvectors, D = Eigenvalues [V D] = eig(A) %% Matlab checks for ill conditioned problems %% e.g. inverse of Hilbert matrix inv(hilb(12)) cond(hilb(12)) %% The dot product, computed two different ways y*x %% row * column dot(x,y) %% The product of a column vector with a row vector gives a matrix y * x %% The cross product cross(x,y) %% Normalize a vector in the Frobenious norm x / norm(x, 'fro') %% Normalize a vector in the Lpi norm x / norm(x, pi)