Prev: calllib function problem: Index exceeds matrix dimensions
Next: repeatedly set Cdata returns out of memory
From: Chanpreet on 16 Jul 2010 06:37 dear all i need to solve a linear system of equations AX= b with constraints min x's 0<x<0.5 A is 5X6 matrix X is 6X1 matrix and b is 5X1 matrix i am using linprog annd Lsqlin i got values of x from both methods but to check it A*X is not equal to b please help me to solve this here is the code i m using matrix_i=[382.5 1183.8;429.1 1136;484 483;684 52.8;820.8 0]; r_i= [61.55,2436.6, 1156.3, 494.7]; a = 0.5; %par= [120.22;243.0811;288.4450;360.33;480.58]; par_tar = [121.68;243.61;291.9;366.12;486.47]; par_des = tuning_matrix(matrix_i,r_i); % 20 cent higher matt= [matrix_i(1,:);matrix_i(2,1)+a, matrix_i(2,2);matrix_i(3:end,:)]; [STEMW1]= tuning_matrix(matt,r_i); p1=par_des-STEMW1; matt= [matrix_i(1:2,:);matrix_i(3,1)+a, matrix_i(3,2);matrix_i(4:end,:)]; [STEMW2]= tuning_matrix(matt,r_i); p2=par_des-STEMW2; matt= [matrix_i(1:3,:);matrix_i(4,1)+a, matrix_i(4,2);matrix_i(5:end,:)]; [STEMW3]= tuning_matrix(matt,r_i); p3=par_des-STEMW3; r= [r_i(1),r_i(2)-a,r_i(3:end)]; [STEMW4]= tuning_matrix(matrix_i,r); p4=par_des-STEMW4; r= [r_i(1:2),r_i(3)-a,r_i(4:end)]; [STEMW5]= tuning_matrix(matrix_i,r); p5=par_des-STEMW5; r= [r_i(1:3),r_i(4)-a,r_i(5:end)]; [STEMW6]= tuning_matrix(matrix_i,r); p6=par_des-STEMW6; T = [p1,p2,p3,p4,p5,p6] % tuning matrix delta_p = par_des-par_tar; lb = zeros(6,1); ub= 0.5*ones(6,1); %f = -ones(1,6); % - for minimisation %a = linprog(f,T,delta_p,[],[],lb,ub) %a= linsolve(T,delta_p); % solves A*X = B a = Lsqlin(T,delta_p,[],[],[],[],lb,ub) hope someone can help me thanks in advance
From: John D'Errico on 16 Jul 2010 08:04
"Chanpreet " <c.kaur(a)tue.nl> wrote in message <i1pcog$l8j$1(a)fred.mathworks.com>... > dear all > i need to solve a linear system of equations > AX= b > with constraints min x's > 0<x<0.5 > A is 5X6 matrix > X is 6X1 matrix > and b is 5X1 matrix > > i am using linprog annd Lsqlin > > i got values of x from both methods but to check it > A*X is not equal to b > please help me to solve this The Rolling Stones said it this way... http://www.youtube.com/watch?v=XIX0ZDqDljA > here is the code i m using > matrix_i=[382.5 1183.8;429.1 1136;484 483;684 52.8;820.8 0]; > r_i= [61.55,2436.6, 1156.3, 494.7]; > a = 0.5; > %par= [120.22;243.0811;288.4450;360.33;480.58]; > par_tar = [121.68;243.61;291.9;366.12;486.47]; > par_des = tuning_matrix(matrix_i,r_i); % 20 cent higher What exactly does tuning_matrix do? "20 cent higher" is not meaningful as a comment. In fact, it makes no cents at all. > matt= [matrix_i(1,:);matrix_i(2,1)+a, matrix_i(2,2);matrix_i(3:end,:)]; > [STEMW1]= tuning_matrix(matt,r_i); > p1=par_des-STEMW1; > matt= [matrix_i(1:2,:);matrix_i(3,1)+a, matrix_i(3,2);matrix_i(4:end,:)]; > [STEMW2]= tuning_matrix(matt,r_i); > p2=par_des-STEMW2; > matt= [matrix_i(1:3,:);matrix_i(4,1)+a, matrix_i(4,2);matrix_i(5:end,:)]; > [STEMW3]= tuning_matrix(matt,r_i); > p3=par_des-STEMW3; > r= [r_i(1),r_i(2)-a,r_i(3:end)]; > [STEMW4]= tuning_matrix(matrix_i,r); > p4=par_des-STEMW4; > r= [r_i(1:2),r_i(3)-a,r_i(4:end)]; > [STEMW5]= tuning_matrix(matrix_i,r); > p5=par_des-STEMW5; > r= [r_i(1:3),r_i(4)-a,r_i(5:end)]; > [STEMW6]= tuning_matrix(matrix_i,r); > p6=par_des-STEMW6; > T = [p1,p2,p3,p4,p5,p6] % tuning matrix > delta_p = par_des-par_tar; > lb = zeros(6,1); > ub= 0.5*ones(6,1); > %f = -ones(1,6); % - for minimisation > %a = linprog(f,T,delta_p,[],[],lb,ub) > %a= linsolve(T,delta_p); % solves A*X = B > a = Lsqlin(T,delta_p,[],[],[],[],lb,ub) > > hope someone can help me > thanks in advance I can't guess what you are doing in all of this. I can't also guess why you are trying to use linprog to solve a linear system of equations. Would you try to use a hammer to turn a screw? But I will state that there is no assurance that a linear system of equations under bound constraints will have an exact solution. Again, the Rolling Stones said it this way... http://www.youtube.com/watch?v=XIX0ZDqDljA John |