You may have some additional problems but one is that you reset wb to zero with every loop iteration, first line in your loop is
wb=0
So although wb get set to the minimum value in your if statement, it immediately gets wiped out in the next loop iteration
I would suggest that rather than finding the minimum yourself with the if statements you just caculate a vector of rho_Tw values and then use MATLAB's min function like this
AA = [2 0 -2 0 0 0 0 0 0 0;
0 2 0 -2 0 0 0 0 0 0;
0 -1 7 -2 -3 0 0 0 0 0;
0 0 0 1 -1 0 0 0 0 0;
0 0 0 0 4 0 0 -2 0 0;
0 0 0 0 0 1 0 0 0 -1;
-2 0 0 0 0 0 2 0 0 0;
0 0 -4 0 0 -1 0 8 -3 0;
0 0 0 0 0 -2 0 0 7 -4;
0 0 0 0 0 0 -3 0 0 4];
L = -tril(AA, -1);
U = -triu(AA, 1);
D = diag(AA);
DD = diag(D);
Tj=inv(DD)*(L+U);
rho_Tj=max(abs(eig(Tj)));
% assign w vector
w = 0:0.0005:2;
% preallocate array to hold rho_Tw values
rho_Tw = zeros(length(w),1);
% loop to evaluate rho_Tw as a function of w
for k = 1:length(w)
Tw=inv(DD-w(k)*L)*(((1-w(k))*DD)+(w(k)*U));
rho_Tw(k) =max(abs(eig(Tw)));
end
% find minimum
[rho_min,idxMin] = min(rho_Tw);
wb = w(idxMin);
% plot results
scatter(w,rho_Tw)
% display results
disp(rho_min)
disp(wb)
