Professional Documents
Culture Documents
ID No:PGR/24532/14
( ) ( √ )
( ) ( √
Then obtain the solution using the MATLAB function.
Solutions:
The problem is minimization problem.
There are about Five constraints:
Three of them are linear inequality constraints.
While two of them are nonlinear inequality constraints.
Algorithms:
1. Define linear equality and inequality constraints as it is given:
A=[0.0156 0 0 -1;0 0 0.0156 -1;0 1 -1 0];
B=[-0.15;-0.15;0];
Aeq and Beq linear equality constraints is not defined so skip ([]).
2. Defined Lower and upper bounds by:
LB=[0;0;0;1.05];UB=[100;100;100;5];
3. Initialize the input by:
x0=UB+(UB-LB).*rand(4,1)
x0 may be a scalar, vector, or matrix.
4. Use MATLAB function syntax given by:
[x,fval]=fmincon(@fun,x0,A,B,[],[],LB,UB,@nonlcon)
Then
1) Draw the feasible region.
2) Find the solution using the MATLAB linear programming function.
3) Find the solution using the MATLAB optimvar and optimproblem function.
MATLAB Code to obtain solution:
1) Draw the feasible region
%Project1Problem2
x1=0:0.01:10;
x2=x1;
gx1=-x1+10;
gx2=x1-3;
gx3=-5/4*x1+35/4;
hold on
xp=[0 10 0];yp=[0 0 10];
patch(xp,yp,[0.91 0.94 0.93])
xp=[0 7 0];yp=[0 0 35/4];
patch(xp,yp,'y');
xp=[3 12 12];yp=[0 0 9];
patch(xp,yp,[0.9 0.9 0.9]);
xp=[3 7 5.222];yp=[0 0 2.2222];
patch(xp,yp,'b');
plot(x1,gx1,x1,gx2,x1,gx3,'b','linewidth',2);
grid on
Optimization Methods (PCE8306) Page 4
axis([0 10 -4 10]);
xlabel('x1')
ylabel('x2')
solution Obtained
ans =39.4444
*These are the value of x at which the value of the function is minimum within a given
constraints.
1) Obtain the solution using the MATLAB linear Program function.
2) Obtain the solution using the MATLAB optimvar and optimproblem functions.
MATLAB Code to obtain solution:
%Project1Problem3
1) Obtain the solution using the MATLAB linprog function
%it is linear program maximization problem z=6*x1+10*x2+9*x3+20*x4
%define as min z=-cx
%so min z=-6*x1-10*x2-9*x3-20*x4
c= [-6 -10 -9 -20];
% Z is subjected to the two linear inequality and one linear equality constraints
A= [4 9 7 10;1 1 3 8]; B= [600;420];
%one linear equality constraints are defined as follows
Aeq=[30 40 20 10]; Beq=800;
%since bounds are given, define as follows
LB= [0;0;0;0]; UB= [inf;inf;inf;inf];
[x,fval]= linprog(c,A,B,Aeq,Beq,LB,UB);
x
-fval
Optimal solution found.
tableoptimvar =
1×4 table
x1 x2 x3 x4
__ ______ __ ______
0 7.0968 0 51.613
ans =1.1032e+03