% operation on vectors and matrices % matrix creation A A = [1 2 3; 3 4 5]; % matrix transposition A' or transpose(A) A' % matrix multiplication B = [4 5; 6 7; 8 9]; A*B % matrix elements multiplication A.*B % cubic power of A (trivial) n = 3; A^3 % A.^C C = [ 1 2 1; 2 1 2]; A.^C % det(A) (?!) make from the matrix A a square matrix and then find its determinant D1 = A(:, 1:2) det(D1) % or D2 = [A(:, 1), A(:, 3)] det(D2) % the main diagonal diag(A) % try to find the difference between D \ B and inv(D)*B % when D is a rectangular matrix inv(D) does not exist % put D = [1 4; 7 2; 9 1]; % then exists D \ B % and D / B % exists as well. % Let's check the interpretation of the \ or / division in the case of rectangular matrices. % a pseudo-inverse matrix % find size of D s = size(D); % find rank of D r = rank(D); % transpose matrix D E = D' % and the inverse matrix G = inv(E*D) % define a matrix K of [r, m] size K = [4 5 1; 3 8 4]; % and finally: Dpseudo = G*E + K*(ones(size(K, 2), size(K, 2)) - D*G*E) % the pseudo-inverse matrix % the matrix A: A = [1 0 1 1; 0 -1 -1 -2; -1 1 0 1]; % the rank of A rA = rank(A); % as B matrix we take a matrix built from rA columns of A that are independent each other B = A(:, 1:rA); % check the rank of B rB = rank(B); % as C matrix we take % C = [eye(2), c1, ..., c(n-rA)] % e.g.: % A =[1 0 -1; 0 1 0; 0 -1 0] % B = A(:, 1:2) % c1 => c(rA + 1) %A(1,rA+1) = B(1, :)*c(rA+1) %A(2,rA+1) = B(2, :)*c(rA+1) % => %A(1:rA, rA+1) = B(1:rA, :)*c(rA+1) % => for the first vector c %c1 = inv(B(1:rA, :))*A(1:rA, rA+1) %and so on for others then we have C % we are back to our example % we need vectors c: c1 and c2 c1 = inv(B(1:rA, :))*A(1:rA, rA+1); c2 = inv(B(1:rA, :))*A(1:rA, rA+2); % or more generally Bprim = inv(B(1:rA, :)); for i=1:size(A, 2)-rA c(:,i) = Bprim*A(1:rA, rA+i); end % then C = [eye(rA), c]; % then we need to find pseudo-inverse matrices to B and C B2 = B'; % the pseudo-inverse matrix as left inverse because rank(B) = size(B, 2) B3 = inv(B2*B); B4 = B3*B2; % and for C C2 = C'; % the pseudo-inverse matrix as right inverse because rank(C) = size(C, 1) C3 = inv(C*C2); C4 = C2*C3; % and the seeked pseudo-inverse matrix of A is A4 = C4*B4; % then one can check the result with the outcome of the \ operator % let's take the matric G G = [3 4; 1 3; 1 2]; Gout1 = A4*G; Gout2 = A\G; % check if they are the same: Gout1 == Gout2 % full agreement should give matrix of (logical) ones => true