Advertisement
ogiorgil

LDLT pivot

Oct 16th, 2022 (edited)
647
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Octave 0.71 KB | None | 0 0
  1. function [ L, d, p ] = LdLT_pivot( A )
  2.   % A is symmetric matrix
  3.   [n, n] = size(A);
  4.   d = [1:n];
  5.   L = eye(n);
  6.   p = [1:n];
  7.   for col = 1:n-1
  8.     display("NEW COL");
  9.     display(A);
  10.     [x, t] = max(abs(diag(A(col:n,col:n))));
  11.     t = t + col - 1;
  12.     display(col);
  13.     display(t);
  14.  
  15.     p([col t]) = p([t col]);
  16.  
  17.     A([col t], :) = A([t col], :);
  18.     A(:, [col t]) = A(:, [t col]);
  19.  
  20.     L([col t], 1:col-1) = L([t col], 1:col-1);
  21.  
  22.     d(col) = A(col, col);
  23.  
  24.     L(col+1:n, col) = A(col, col+1:n)' / d(col);
  25.     display("after swap");
  26.     display(A);
  27.     for row = col+1:n
  28.       A(row, row:n) = A(row, row:n) - L(row, col) * A(col, row:n);
  29.     endfor
  30.   endfor
  31.   d(n) = A(n, n);
  32.  
  33. endfunction
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement