using Plots # nice viz for matrices function lookat(A; redrow=0, rounding=2, showtext=true) n = size(A,1) plot(legend=false, axis=false) rowcolor = redrow > 0 ? :red : :black for i=1:n, j=1:n scatter!( [j],[i], ann= showtext ? (j,i,round(A[i,j],digits=rounding), :white ) : (j,i,"") , color=abs(A[i,j]) > .0001 ? (i==redrow ? rowcolor : :black) : :white, marker=:square, markersize=30, aspectratio=1, yflip=true, yaxis=[.5,n+.5],xaxis=[.5,n+.5]) end plot!() end A = rand(1.0:9,4,4) L = fill(0.0,4,4) lookat(A) L[2,1] = A[2,1] / A[1,1] # A[2,:] = A[2,:] - L[2,1] * A[1,:] A[2,:] -= L[2,1] * A[1,:] # subtract that multiple of the first row from the second lookat(A, redrow=2) L[3,1] = A[3,1] / A[1,1] A[3,:] -= L[3,1] * A[1,:] lookat(A, redrow=3) L[4,1] = A[4,1] / A[1,1] A[4,:] -= L[4,1] * A[1,:] lookat(A, redrow=4) L[3,2] = A[3,2] / A[2,2] A[3,:] -= L[3,2] * A[2,:]; lookat(A, redrow=3) L[4,2] = A[4,2] / A[2,2]; A[4,:] -= L[4,2] * A[2,:]; lookat(A, redrow=4) n = 5 A = randn(n,n) L = fill(0.0,n,n) display(lookat(A)) for j=1:n, i=(j+1):n L[i,j] = A[i,j]/A[j,j] A[i,:] -= L[i,j] * A[j,:] display(lookat(A,redrow=i)) end n = 5 A = randn(n,n) L = fill(0.0,n,n) Akeep = [copy(A)] row = [0] display(lookat(A)) for j=1:n, i=(j+1):n L[i,j] = A[i,j]/A[j,j] A[i,:] -= L[i,j] * A[j,:] push!(Akeep,copy(A)) push!(row,i) end using Interact @manipulate for i=slider(1:length(Akeep),value=1) lookat(Akeep[i],redrow=row[i],showtext=true) end using LinearAlgebra U = Akeep[end] A = Akeep[1] L += I L*U A L*U ≈ A