필터 지우기
필터 지우기

Linear programming (having upper and lower limit)

조회 수: 2 (최근 30일)
Mohammad Yunus Ali
Mohammad Yunus Ali 2011년 3월 21일
I need help to write code for linear programming like below.
Minimize Z=5*x1+2*x2-3
Subject to x1+2x2=6 -1<x1<2 0<x2<1
  댓글 수: 3
Mohammad Yunus Ali
Mohammad Yunus Ali 2011년 3월 21일
I wrote a code like below. but not running
clc
clear all
% minimizing f(x) = –5x1 – 4x2 –6x3, subject to
% x1 – x2 + x3 ? 20
% 3x1 + 2x2 + 4x3 ? 42
% 3x1 + 2x2 ? 30
% 0 ? x1, 0 ? x2, 0 ? x3.
f = [-5; -4; -6];
A = [1 -1 1
3 2 4
3 2 0];
b = [20; 42; 30];
lb = zeros(3,1);
Aeq=[];
beq=[];
x = linprog(f,A,b,Aeq,beq,lb);
Andrew Newell
Andrew Newell 2011년 3월 21일
Assuming the question marks represent <=, this code works fine on my machine. Do you have the Optimization Toolbox?

댓글을 달려면 로그인하십시오.

답변 (1개)

Andrew Newell
Andrew Newell 2011년 3월 21일
I assume that the above code is not working because you don't have the Optimization Toolbox. You can download Revised Simplex Method from the File Exchange and use fairly similar code:
clc
clear all
% minimizing f(x) = –5x1 – 4x2 –6x3, subject to
%
% x1 – x2 + x3 <= 20
% 3x1 + 2x2 + 4x3 <= 42
% 3x1 + 2x2 <= 30
% 0 <= x1, 0 <= x2, 0 <= x3.
f = [-5 -4 -6];
A = [1 -1 1
3 2 4
3 2 0];
b = [20 42 30];
inq = [-1 -1 -1];
minimize = 1;
revised(f,b,A,inq,minimize)
This gives some diagnostic code followed by
The optimum solution is:
x1 = 0
x2 = 15
x3 = 3
  댓글 수: 2
Mohammad Yunus Ali
Mohammad Yunus Ali 2011년 3월 22일
Thanks for your reply. But the code is not running. Its showing error. like below:
??? Undefined function or method 'revised' for input arguments of type 'double'.
Error in ==> linpr at 9
revised(f,b,A,inq,minimize)
could you pls write a complete code for me.
Andrew Newell
Andrew Newell 2011년 3월 22일
Did you download the code and add the folder containing it to your path?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Downloads에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by