In the LU decomposition method, I used a 4*5 matrix. However, L and U should originally come out as 4*5 matrices, but both come out only 4*4 matrices. What is the cause?
1 view (last 30 days)
Show older comments
function [L,U] = LU(A)
A = [4 -2 -3 6 12;-6 7 6.5 -6.5 -6.5;1 7.5 6.25 5.5 16;-12 22 15.5 -1 17];
[m,n] = size(A);
for i = 1:m
L(i,1) = A(i,1);
U(i,i) = 1;
end
for j = 2:m
U(1,j)= A(1,j)/L(1,1);
end
for i = 2:m
for j = 2:i
L(i,j)=A(i,j)-L(i,1:j-1)*U(1:j-1,j);
end
for j = i+1:m
U(i,j)=(A(i,j)-L(i,1:i-1)*U(1:i-1,j))/L(i,i);
end
end
L
U
----------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------
so. The answer comes out like this, but what is the problem here >>??? And I only need to show L U, but I don’t know if ans comes............
L =
4.0000 0 0 0
-6.0000 4.0000 0 0
1.0000 8.0000 3.0000 0
-12.0000 16.0000 -1.5000 6.5000
U =
1.0000 -0.5000 -0.7500 1.5000
0 1.0000 0.5000 0.6250
0 0 1.0000 -0.3333
0 0 0 1.0000
ans =
4.0000 0 0 0
-6.0000 4.0000 0 0
1.0000 8.0000 3.0000 0
-12.0000 16.0000 -1.5000 6.5000
0 Comments
Answers (0)
See Also
Categories
Find more on Matrix Decomposition in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!