% RESENI POMOCI LU-ROZKLADU:
load LRmat1
A
A =
      3            2            1
      2            3            1
      2            1            3
      5            5            2
b
b =
      5
      1
     11
      6
[L,U,p,jb] = LUdemo(A)
m =
      4
n =
      3
A =
      3            2            1            1
      2            3            1            2
      2            1            3            3
      5            5            2            4
Vlozte polohu dalsiho schodu ve tvaru [r,s]: [4 1]
r =
      4
jb =
      1
k =
      1
PREHOZENI k-ho a r-teho RADKU:
A =
      5            5            2            4
      2            3            1            2
      2            1            3            3
      3            2            1            1
ULOZENI TRANSFORMACNICH SKALARU MISTO NUL DO s-teho SLOUPCE:
A =
      5            5            2            4
     2/5           3            1            2
     2/5           1            3            3
     3/5           2            1            1
ELIMINACE ZBYVAJICICH SLOUPCU s+1,...,n:
A =
      5            5            2            4
     2/5           1           1/5           2
     2/5          -1          11/5           3
     3/5          -1          -1/5           1
Posledni eliminovany sloupec:
s =
      1
Vlozte polohu dalsiho schodu ve tvaru [r,s]: [2 2]
rs =
      2            2
r =
      2
jb =
      1            2
k =
      2
Zamena radku se neprovadi
ULOZENI TRANSFORMACNICH SKALARU MISTO NUL DO s-teho SLOUPCE:
A =
      5            5            2            4
     2/5           1           1/5           2
     2/5          -1          11/5           3
     3/5          -1          -1/5           1
ELIMINACE ZBYVAJICICH SLOUPCU s+1,...,n:
A =
      5            5            2            4
     2/5           1           1/5           2
     2/5          -1          12/5           3
     3/5          -1            0            1
Posledni eliminovany sloupec:
s =
      2
Vlozte polohu dalsiho schodu ve tvaru [r,s]: 3
rs =
      3
jb =
      1            2            3
L =
      1            0            0            0
     2/5           1            0            0
     2/5          -1            1            0
     3/5          -1            0            1
U =
      5            5            2
      0            1           1/5
      0            0          12/5
      0            0            0
p =
      4
      2
      3
      1
jb =
      1            2            3
% Kontrola
A(p,:)-L*U
ans =
      0            0            0
      0            0            0
      0            0            *
      0            0            0
A(p,:)
ans =
      5            5            2
      2            3            1
      2            1            3
      3            2            1
L*U
ans =
      5            5            2
      2            3            1
      2            1            3
      3            2            1
% Resime L*z = b(p):
z = L\b(p)
z =
      6
    -7/5
    36/5
      0
% Resime U*x=z:
[U,z]
ans =
      5            5            2            6
      0            1           1/5         -7/5
      0            0          12/5         36/5
      0            0            0            0
% Neni schod navic => system je resitelny
% hodnost je 3: pocet sloupcu-3=0 => jedine reseni:
x = U\z
x =
      2
     -2
      3
diary off
*****************************************************
load LRmat2
A
A =
      5           -9            5
      2            3            3
      1            8            0
      1           -2            1
b
b =
      1
      2
      1
      0
[L,U,p,jb] = LUdemo(A)
m =
      4
n =
      3
A =
      5           -9            5            1
      2            3            3            2
      1            8            0            3
      1           -2            1            4
Vlozte polohu dalsiho schodu ve tvaru [r,s]: [4 1]
r =
      4
jb =
      1
k =
      1
PREHOZENI k-ho a r-teho RADKU:
A =
      1           -2            1            4
      2            3            3            2
      1            8            0            3
      5           -9            5            1
ULOZENI TRANSFORMACNICH SKALARU MISTO NUL DO s-teho SLOUPCE:
A =
      1           -2            1            4
      2            3            3            2
      1            8            0            3
      5           -9            5            1
ELIMINACE ZBYVAJICICH SLOUPCU s+1,...,n:
A =
      1           -2            1            4
      2            7            1            2
      1           10           -1            3
      5            1            0            1
Posledni eliminovany sloupec:
s =
      1
Vlozte polohu dalsiho schodu ve tvaru [r,s]: [4 2]
rs =
      4            2
r =
      4
jb =
      1            2
k =
      2
PREHOZENI k-ho a r-teho RADKU:
A =
      1           -2            1            4
      5            1            0            1
      1           10           -1            3
      2            7            1            2
ULOZENI TRANSFORMACNICH SKALARU MISTO NUL DO s-teho SLOUPCE:
A =
      1           -2            1            4
      5            1            0            1
      1           10           -1            3
      2            7            1            2
ELIMINACE ZBYVAJICICH SLOUPCU s+1,...,n:
A =
      1           -2            1            4
      5            1            0            1
      1           10           -1            3
      2            7            1            2
Posledni eliminovany sloupec:
s =
      2
Vlozte polohu dalsiho schodu ve tvaru [r,s]: [3 3]
rs =
      3            3
r =
      3
jb =
      1            2            3
k =
      3
Zamena radku se neprovadi
ULOZENI TRANSFORMACNICH SKALARU MISTO NUL DO s-teho SLOUPCE:
A =
      1           -2            1            4
      5            1            0            1
      1           10           -1            3
      2            7           -1            2
ELIMINACE ZBYVAJICICH SLOUPCU s+1,...,n:
A =
      1           -2            1            4
      5            1            0            1
      1           10           -1            3
      2            7           -1            2
Posledni eliminovany sloupec:
s =
      3
Vlozte polohu dalsiho schodu ve tvaru [r,s]: rs =
     []
jb =
      1            2            3
L =
      1            0            0            0
      5            1            0            0
      1           10            1            0
      2            7           -1            1
U =
      1           -2            1
      0            1            0
      0            0           -1
      0            0            0
p =
      4
      1
      3
      2
jb =
      1            2            3
A(p,:)
ans =
      1           -2            1
      5           -9            5
      1            8            0
      2            3            3
L*U
ans =
      1           -2            1
      5           -9            5
      1            8            0
      2            3            3
% Resime L*z = b(p):
z = L\b(p)
z =
      0
      1
     -9
    -14

% Resime U*x=z:
[U,z]
ans =
      1           -2            1            0
      0            1            0            1
      0            0           -1           -9
      0            0            0          -14

% V poslednim sloupci je jeden schod navic, takze reseni neexistuje
*****************************************************************

diary off
load LRmat3
A
A =
      2           -3            2
      1           -2            1
      5           -9            5
b
b =
      1
      0
      1
[L,U,p,jb] = LUdemo(A)
m =
      3
n =
      3
A =
      2           -3            2            1
      1           -2            1            2
      5           -9            5            3
Vlozte polohu dalsiho schodu ve tvaru [r,s]: [2 1]
r =
      2
jb =
      1
k =
      1
PREHOZENI k-ho a r-teho RADKU:
A =
      1           -2            1            2
      2           -3            2            1
      5           -9            5            3
ULOZENI TRANSFORMACNICH SKALARU MISTO NUL DO s-teho SLOUPCE:
A =
      1           -2            1            2
      2           -3            2            1
      5           -9            5            3
ELIMINACE ZBYVAJICICH SLOUPCU s+1,...,n:
A =
      1           -2            1            2
      2            1            0            1
      5            1            0            3
Posledni eliminovany sloupec:
s =
      1
Vlozte polohu dalsiho schodu ve tvaru [r,s]: [2 2]
rs =
      2            2
r =
      2
jb =
      1            2
k =
      2
Zamena radku se neprovadi
ULOZENI TRANSFORMACNICH SKALARU MISTO NUL DO s-teho SLOUPCE:
A =
      1           -2            1            2
      2            1            0            1
      5            1            0            3
ELIMINACE ZBYVAJICICH SLOUPCU s+1,...,n:
A =
      1           -2            1            2
      2            1            0            1
      5            1            0            3
Posledni eliminovany sloupec:
s =
      2
Vlozte polohu dalsiho schodu ve tvaru [r,s]: rs =
     []
jb =
      1            2
L =
      1            0            0
      2            1            0
      5            1            1
U =
      1           -2            1
      0            1            0
      0            0            0
p =
      2
      1
      3
jb =
      1            2
% Kontrola:
A(p,:)
ans =
      1           -2            1
      2           -3            2
      5           -9            5
L*U
ans =
      1           -2            1
      2           -3            2
      5           -9            5
% Resime L*z = b(p):
z = L\b(p)
z =
      0
      1
      0

% Resime U*x=z:
[U,z]
ans =
      1           -2            1            0
      0            1            0            1
      0            0            0            0

% Neni schod navic => reseni existuje
% pocet sloupcu - hodnost = 3 - 2 = 1
% x3 = t je volna promenna
% Partikularni reseni
t=0
t =
      0
y = U(1:2,1:2)\z(1:2)
y =
      2
      1
x0=[y;t]
x0 =
      2
      1
      0
% Baze:
t=1
t =
      1
y = U(1:2,1:2)\(-U(1:2,3))
y =
     -1
      0
x1=[y;t]
x1 =
     -1
      0
      1
% Vsechna reseni: x0+t*x1 = [2,1,0]+t*[-1,0,1]=[2-t,1,t]
diary off
