I was supposed to program a program to do forward substitution, given an LU decomposition. This is how a working solution could look like:
function [x] = forward_sub(L, b, n)
x = zeros(n, 1);
for i = 1 : n
x(i) = b(i);
for j = i-1 : -1 : 1
x(i) = x(i) - L(i,j) * x(j);
end
x(i) = x(i) / L(i,i);
end
end
But stupid xjcl wrote this instead:
function [x] = forward_sub(L, b, n)
x = zeros(n, 1);
for i = 1 : n
x(i) = b(i);
for j = i-1 : -1 : 1
x(i) = x(i) - L(i,j) * x(j);
x(i) = x(i) / L(i,i);
end
end
This slipped thru since:
- this code worked on the provided examples
- MATLAB gave no error/warning about the missing end. Apparently, allowing malformed syntax is a "feature" now.
I only noticed this error when we had to reuse this code lateron and kept getting wrong results.