How to run please this example perfectly to get optimal solution .. Thank you

1 次查看(过去 30 天)
f = [0 ; - 10 ; 0 ; - 6; - 20] ;
A = [1 0 0 0 0 ;
0 1 0 0 0 ;
0 0 1 0 0 ;
0 0 0 1 0 ;
0 0 0 0 1] ;
B = [4 ; 3 ; 3 ; 2 ; 2] ;
Aeq = [1 - 1 - 1 0 0 ; 0 0 1 - 1 - 1] ;
beq = [0; 0; 0; 0; 0];
lb = zeros (5, 1) ;
ub = zeros (5, 1) ;
x = linprog(f,A,B,Aeq,beq,lb,ub)
[x,fval] = linprog(f,A,Aeq,beq,lb,ub);

采纳的回答

Steven Lord
Steven Lord 2023-5-4
lb = zeros (5, 1) ;
ub = zeros (5, 1) ;
So based on the way you've constructed the bounds, all the elements of your solution have to be greater than or equal to 0 and less than or equal to 0. The only possible solution that satisfies both sets of bounds is zeros(5, 1).
Are you sure that ub shouldn't be something like ones(5, 1)?
  7 个评论
Steven Lord
Steven Lord 2023-5-4
Yes, I saw that. I would have expected them also to appear in the "Therefore, the problem can be posed as the following linear program:" section as inequalities like the last three bound constraints. But due to a lack of space on the page I wonder if students solving the problem could overlook the last two equations (which I assumed appeared after the diagram on page 262.)

请先登录,再进行评论。

更多回答(1 个)

Torsten
Torsten 2023-5-4
f = [0 ; -10 ; 0 ; -6; -20] ;
A = [1 0 0 0 0 ;
0 1 0 0 0 ;
0 0 1 0 0 ;
0 0 0 1 0 ;
0 0 0 0 1] ;
B = [4 ; 3 ; 3 ; 2 ; 2] ;
Aeq = [1 -1 -1 0 0 ; 0 0 1 -1 -1] ;
beq = [0; 0];
lb = zeros (5, 1) ;
ub = zeros (5, 1) ;
[x,fval] = linprog(f,A,B,Aeq,beq,lb,ub)
Optimal solution found.
x = 5×1
0 0 0 0 0
fval = 0
  2 个评论
Dalia ElNakib
Dalia ElNakib 2023-5-4
f = [0 ; -10 ; 0 ; -6; -20] ;
A = [1 0 0 0 0 ;
0 1 0 0 0 ;
0 0 1 0 0 ;
0 0 0 1 0 ;
0 0 0 0 1] ;
B = [4 ; 3 ; 3 ; 2 ; 2] ;
Aeq = [1 -1 -1 0 0 ; 0 0 1 -1 -1] ;
beq = [0; 0];
lb = zeros (5, 1) ;
ub = ones(5, 1);
[x,fval] = linprog(f,A,B,Aeq,beq,lb,ub);
Optimal solution found.
Dalia ElNakib
Dalia ElNakib 2023-5-4
编辑:Dalia ElNakib 2023-5-4
Thank you so much
Both work to ge the optimal solution
Either:
lb = zeros (5, 1) ;
ub = zeros (5, 1) ;
Or
lb = zeros (5, 1) ;
ub = ones (5, 1) ;
f = [0 ; -10 ; 0 ; -6; -20] ;
A = [1 0 0 0 0 ;
0 1 0 0 0 ;
0 0 1 0 0 ;
0 0 0 1 0 ;
0 0 0 0 1] ;
B = [4 ; 3 ; 3 ; 2 ; 2] ;
Aeq = [1 -1 -1 0 0 ; 0 0 1 -1 -1] ;
beq = [0; 0];
lb = zeros (5, 1) ;
ub = zeros(5, 1);
[x,fval] = linprog(f,A,B,Aeq,beq,lb,ub);
Optimal solution found.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Get Started with Optimization Toolbox 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by