0

I wrote a program implementing Gaussian Elimination with Complete Pivoting:

function x = gecp(A,b)

x = b;
n = length(A);
p = 1:n;    
l = b;     

for k = 1:n
    [i,j] = find(A(k:n,k:n)==max(abs(A(k:n,k:n)),[],'all'));

    i = i+k-1;
    j = j+k-1; 

    [A(k,:),A(i,:)] = deal(A(i,:),A(k,:));
    [A(:,j),A(:,k)] = deal(A(:,k),A(:,j));
    [b(i),b(k)] = deal(b(k),b(i));

    [p(k),p(j)] = deal(p(j),p(k));

    temp = (k+1):n;
    l(temp) = A(temp,k)/A(k,k);
    b(temp) = b(temp)-l(temp).*b(k);


    A(temp,temp) = A(temp,temp)-l(temp).*A(k,temp);
end

x(n) = b(n)/A(n,n);
for k = (n-1):-1:1
    s = 0;
    for h = (k+1):n
        s = s+A(k,h)*x(h);
    end
    x(k) = (b(k)-s)/A(k,k);
end

x(p) = x;

And it is called like this:

N = 5; A = randn(N); b = randn(N,1); x = gecp(A,b)

Unfortunately all lines containing deal function (used for swapping rows of columns of matrices), give me following (or similar) error: "Unable to perform assignment because the size of the left side is 1-by-5 and the size of the right side is 0-by-5."

Unfortunately I have no idead why would the width of these vectors be changed to 0 as I wrote excatly the same thing on both sides.

MartinYakuza
  • 60
  • 1
  • 12

0 Answers0