This commit is contained in:
LinlyBoi
2023-03-21 07:57:45 +02:00
parent 0ae3805887
commit 1060ad7f8a

26
LU.m
View File

@@ -1,32 +1,32 @@
# upper matrix ballocks. # upper matrix.
clear,clc clear,clc
#U2 = -A(2,1)/A(1,1) * A(1, :) + A(2, :) #U2 = -A(2,1)/A(1,1) * A(1, :) + A(2, :)
#U3 = -A(3,1)/A(1,1) * A(1, :) + A(3, :) #U3 = -A(3,1)/A(1,1) * A(1, :) + A(3, :)
#U_temp = [A(1,:); U2; U3]
#U3 = -A(3,2)/U_temp(2,2) * U_temp(2, :) + U_temp(3, :)
#U = [A(1,:); U2; U3] #U = [A(1,:); U2; U3]
#L = [1, 0, 0; A(2,1)/A(1,1),1,0;(A(3,1)/A(1,1)),(A(3,2)/U_temp(2,2)),1] #U3 = -A(3,2)/U(2,2) * U(2, :) + U(3, :)
#U = [A(1,:); U2; U3]
#L = [1, 0, 0; A(2,1)/A(1,1),1,0;(A(3,1)/A(1,1)),(A(3,2)/U(2,2)),1]
# U_temp var = A (matrix) # U var = A (matrix)
# for i < n # for i < n
# j = i + 1 # j = i + 1
# for j <= n # for j <= n
# U_temp(j, :) = -U_temp(j,i)/U_temp(j,i) * U_temp(i, :) + U_temp(j, :) # U(j, :) = -U(j,i)/U(j,i) * U(i, :) + U(j, :)
A = [5,2,4;2,1,1;1,-5,-3]; A = [5,2,4;2,1,1;1,-5,-3];
b = [17;0;13;]; b = [17;0;13;];
U_temp = A U = A
L_temp = eye(3); L = eye(3);
for i = [1:length(A)-1] for i = [1:length(A)-1]
for j = [i+1: length(A)] for j = [i+1: length(A)]
L_temp(j,i) = U_temp(j,i)/U_temp(i,i); L(j,i) = U(j,i)/U(i,i);
U_temp(j, :) = -U_temp(j,i)/U_temp(i,i) * U_temp(i, :) + U_temp(j, :); U(j, :) = -U(j,i)/U(i,i) * U(i, :) + U(j, :);
endfor endfor
endfor endfor
U_temp U
L_temp L
#another for loop that's like we create another matrix for Z #another for loop that's like we create another matrix for Z
L_temp*U_temp\b L*U\b