LU decomposition
Show older comments
Hi, i´m a begginer(looser) in matlab and i don´t know, where is problem in this script. Please help me and thanks for tips.
function [L, U, P] = LURozklad(A)
P = eye(size(A));
L = P;
A_pred = A;
P_pred = P;
for k = 1:size(A) - 1
r = IPR(A, k, k);
A_pred = A;
A = VymenaRadkuMatice(A, k, r);
P_pred = VymenaRadkuMatice(P_pred, k, r);
P = P_predchozi;
for i = k + 1:size(A)
m_ik = A(i, k)/A(k, k);
for j = k + 1:size(A)
A(i, j) = A(i, j) - m_ik * A(k, j);
end
A(i, k) = m_ik;
end
printf('matice A: ', A);
for i = 2:size(A)
for j = 1:size(A)
if i > j
L(i, j) = A(i, j);
end
end
end
printf('matice L: ', L);
for i = 1:size(A)
for j = 1:size(A)
if i <= j
U(i, j) = A(i, j);
end
end
end
printf('matice U: ', U);
P = P_predchozi;
printf('matice P:', P);
end
function [r] = IndexPivotnihoRadku(A, OdRadku, IndexSloupce)
MaxHodnota = 0;
for i = OdRadku:size(A)
if abs(A(i,IndexSloupce)) > MaxHodnota
MaxHodnota = abs(A(i,IndexSloupce));
r = i;
end
end
function [A] = VymenaRadkuMatice(A, radek1, radek2)
PomocnyRadek = A(radek1,:);
A(radek1, :) = A(radek2,:);
A(radek2, :) = PomocnyRadek;
end
function printf(string, value)
disp(string);
disp(value);
end
end
end
1 Comment
Jan
on 12 Mar 2012
Please explain, why you are thinking, that this function has a problem.
Answers (0)
Categories
Find more on Interactive Control and Callbacks 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!