I am having a hard time trying to understand why this Matlab code to perform Gaussian Elimination without pivoting using LU factorization takes (2/3) * n^3
flops. (FLOPs: floating point operations and not FLOPS: floating point operations per second)
function x = GaussianElimination(A,b)
n = length(b);
for k = 1:n-1
for i = k+1:n
mult = A(i,k)/A(k,k);
A(i,k+1:n) = A(i,k+1:n)-mult*A(k,k+1:n);
b(i) = b(i) - mult*b(k);
end
end
x = zeros(n,1);
x(n) = b(n)/A(n,n);
for k = n-1:-1:1
x(k) = (b(k) - A(k,k+1:n)*x(k+1:n))/A(k,k);
end
end
If anyone could explain to me how flops are counted for those nested loops that start at k+1
I would be grateful.
PS: I am not talking about algorithmic complexity here.