# construct a permutation matrix P from the permutation vector p function permutation_matrix(p) P = zeros(Int, length(p),length(p)) for i = 1:length(p) P[i,p[i]] = 1 end return P end P = permutation_matrix([2,4,1,5,3]) "ONE-HOT VECTOR" I₅ = eye(5) P * I₅ P P'*P P*P' A =rand(3,5) A' function my_transpose(A) m,n=size(A) B = zeros(n,m) for i=1:m, j=1:n B[j,i]=A[i,j] end B end A my_transpose(A) A = rand(3,3) B = rand(3,3) (A*B)' B' * A' x = rand(3) y = rand(3) x ⋅ (A*y) # The transpose of A is the unique matrix such that # x ⋅ (A*y) = (A'x)⋅y for all x and y (A'x)⋅y C = rand(-9:9, 4,4) D = rand(-9:9, 4,4) (C*D)' == D'*C' A = [4 -2 -7 -4 -8 9 -6 -6 -1 -5 -2 -9 3 -5 2 9 7 -9 5 -8 -1 6 -3 9 6] inv(A') inv(A)' L,U,p = lu(A) p L' U' b = [4,2,1,-2,3] # "randomly" chosen right-hand side A' \ b # correct solution to Aᵀx = b c = U' \ b # forward-substitution d = L' \ c # backsubstitution permutation_matrix(p)' * d LU = lufact(A) LU' \ b A S = A' + A S' == (A')'+ A' == A +A' == A' + A S = A' * A S' == (A' *A )' == A' * A L, U = lu(S, Val{false}) # LU without pivoting L U diag(U) D = diagm(diag(U)) # diagm makes a diagonal matrix from a 1d array inv(D) inv(D) * U L' S L D = abs.(D) S = L*abs.(D)*L' U = L' L K = L* diagm(sqrt.(diag(D))) K*K' - S # kind of a matrix sqrt: cholesky factorization chol(S) S - S' chol(Symmetric(S)) K'