using LinearAlgebra # load this package for most of Julia's linear algebra functions A = [1 3 1 1 1 -1 3 11 6] # LU factorization (Gaussian elimination) of the matrix A, # passing the NoPivot() to prevent row re-ordering ("pivoting") L, U = lu(A, NoPivot()) U # just show U E1 = [ 1 0 0 -1 1 0 -3 0 1] E1*A using Symbolics @variables s[1:3, 1:3] # declare an bunch of symbolic variables S = collect(s) # & collect them into a matrix E1 * S @variables πŸ˜€ πŸ₯Έ 😭 🐸 🐢 🐨 πŸš— πŸš› 🚜 # declare "moar funner" symbolic variables S = [ πŸ˜€ πŸ₯Έ 😭 # first row = faces 🐸 🐢 🐨 # second row = animals πŸš— πŸš› 🚜 ] # third row = Carsβ„’ E1 * S E2 = [1 0 0 0 1 0 0 1 1] E2 * S E2*E1*A E2*E1*S E2*E1*A == U E = E2*E1 E1*E2 lu(A, NoPivot()) E^-1 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] # a randomly chosen 5x5 matrix b = [-7,2,4,-4,-7] # a randomly chosen right-hand side I(5) I(5) * b == b I(5) * A == A A * I(5) == A I I * b I * A == A == A * I I * [2, 3] B = [2 3 4 5 6 7] I * B * I I(3) * B * I(2) I(2) * B * I(3) # should give an error: wrong-shape matrices! I * B * I inv(A) round.(inv(A) * A, 3) C = rand(4,4) D = rand(4,4) inv(C*D) inv(D)*inv(C) inv(C)*inv(D) # this is not the inverse of C*D A = [1 3 1 1 1 -1 3 11 6] E1 = [ 1 0 0 -1 1 0 -3 0 1] E2 = [1 0 0 0 1 0 0 1 1] E2*E1 E1*E2 inv(E2*E1) E1 E2 inv(E2) inv(E1) L, U = lu(A, Val{false}) U inv(E1)*inv(E2)*U L = inv(E1)*inv(E2) inv(E2*E1) E1 L inv(L) 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] # a randomly chosen 5x5 matrix Ainv = A \ I(5) Ainv - inv(A) Ainv β‰ˆ inv(A) Ainv * A A * Ainv [A\b Ainv*b] # print the two results side-by-side