www.gusucode.com > GAVPai_Book_MathworksCntrlFileEx_May2019 > GAVPai_Book_MathworksCntrlFileEx_May2019/std_excesswgts.m
% function handles Step 2 (Contd.) and Steps 3, 4, 5 and 6, of the Repair % Strategy (see Chapter 4, Sec. 4.5) function std_weight = std_excesswgts(weight_vec, low_up_bounds, bassetsindx) [row_mat, col_mat]=size(weight_vec); % Step 2 Contd. % find excess weights and shear off equal portions of the excess from % each of the weights Sum_Wgts =sum(weight_vec); Decr_amt = (Sum_Wgts-1)/col_mat; weight_vec= weight_vec-Decr_amt; % Steps 3, 4 and 5 of Repair Strategy % partition weights as R and Q R=[]; c_R=0; len= length(bassetsindx); for j=1:len j_indx= bassetsindx(j); if (weight_vec(1,j_indx)< low_up_bounds(1,j_indx)) weight_vec(1,j_indx)= low_up_bounds(1,j_indx); c_R = c_R+1; R(c_R) = j_indx; end end % Q and R work to adjust excess weights ex_flag = true; while (ex_flag == true) ex_flag = false; Q = setdiff([1:col_mat], R); L = sum(weight_vec); F = L-1; len_Q= length(Q); Decr_amt=F/len_Q; for j = 1: len_Q weight_vec(1, Q(j)) = weight_vec(1,Q(j))-Decr_amt; if (ismember(Q(j), bassetsindx)) if (weight_vec(1, Q(j)) < low_up_bounds(1, Q(j))) weight_vec(1, Q(j)) = low_up_bounds(1,Q(j)); ex_flag = true; c_R = c_R+1; R(c_R) = Q(j); end end end end % end while % Step 6 of Repair Strategy Sum_Wgts =sum(weight_vec); if(Sum_Wgts <1) Incr_amt = (1-Sum_Wgts)/col_mat; weight_vec = weight_vec+Incr_amt; end std_weight = weight_vec; end