Trying to find a minimum value
Show older comments
In this code, I am trying to find the minimum value of rho_Tw, and find the associated w value with it (so basically trying to find the x value associated with the minimum y value). However, whenever I run the following code, I get 0. Any corrections would be greatly appreciated.
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)));
for w = 0:0.0005:2
wb=0;
rho_min=0;
Tw=inv(DD-w*L)*(((1-w)*DD)+(w*U));
rho_Tw=max(abs(eig(Tw)))
scatter(w, rho_Tw)
hold on
if w == 0
rho_min = rho_Tw;
wb = w;
end
if rho_Tw < rho_min
rho_min = rho_Tw;
wb=w;
end
end
disp(wb)
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!