You are on page 1of 8

Adama Science and Technology University

Department of Electrical Power and Control Engineering

Optimization Method (PCE8306)


Project#1
Prepared By:Tahir Kedir

ID No:PGR/24532/14

Submitted To: Prof. Gang Gyoo Jin

Due Date: Jan11, 2022

Optimization Methods (PCE8306) Page 1


Problem1.The minimum weight-design of the corrugated bulkheads for a tanker requires the
solution of the following optimization problem, where the variables correspond to the
following corrugation dimension: width, depth, length, and plate thickness:
( )
( )

 ( ) ( √ )

 ( ) ( √





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)

Optimization Methods (PCE8306) Page 2


5. Define nonlinear equality and inequality constraints as it is given:
 nonlinear inequality constraints are defined by:
 [c,ceq]=nonlcon(x)
Where:
 c is nonlinear inequality constraints
 ceq nonlinear equality constraints is not defined so skip([]) it.
MATLAB Code to obtain solution
function Project1problem1
A=[0.0156 0 0 -1;0 0 0.0156 -1;0 1 -1 0];
B=[-0.15;-0.15;0];
LB=[0;0;0;1.05];UB=[100;100;100;5];
x0=UB+(UB-LB).*rand(4,1)
[x,fval]=fmincon(@fun,x0,A,B,[],[],LB,UB,@nonlcon)
c=nonlcon(x)
function f=fun(x)
f=5.885*x(4)*(x(1)+x(3))/(x(1)+sqrt(x(3)^2-x(2)^2));
%f accepts input x and returns a scalar function value f evaluated at x.
function [c,ceq]=nonlcon(x)
temp=8.94*(x(1)+sqrt(x(3)^2-x(2)^2));
%nlcon accepts x and returns the vectors c and ceq.
ceq=[];
c(1)=-x(2)*x(4)*(0.4*x(1)+x(3)/6)+temp;
c(2)=-x(2)^2*x(4)*(0.2*x(1)+x(3)/12)+2.2*temp^(4/3);
Optimal solution found:
Local minimum found that satisfies the constraints.
Optimization completed because the objective function is non-decreasing in feasible directions,
to within the value of the optimality tolerance, and constraints are satisfied to within the value of
the constraint tolerance.
<stopping criteria details>
x = 57.6923 34.1476 57.6923 1.0500 fval =6.8430 c = -240.6946 -0.0005
*These are the value of x at which the value of the function is minimum within a given
constraints.

Optimization Methods (PCE8306) Page 3


Problem 2.Consider the following Linear Program (LP):





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

Figure: shows constraints


2) Find the solution using the MATLAB linprog function
%it is linear program maximization problem z=5x1+6x2
%define as min z=-cx
%so min z=-5x1-6x2
c= [-5 -6];
% Z is subjected to the three linear inequality constraints
A= [1 1;-1 1;5 4]; B= [10;-3;35];
%linear equality constraints are not defined so skip it []
%since bounds are given define as follows
LB= [0;0]; UB= [inf;inf];
[x,fval]= linprog(c,A,B,[],[],LB,UB);
x
-fval
Optimal solution found.
x = 5.2222 2.2222
ans = 39.4444
*These are the value of x at which the value of the function is minimum within a given
constraints.

Optimization Methods (PCE8306) Page 5


3) Find the solution using the MATLAB optimvar and optimproblem functions
% Define all problem variables with the bounds.
x1 = optimvar('x1','LowerBound',0,'UpperBound',inf);
x2 = optimvar('x2','LowerBound',0,'UpperBound',inf);
% Create the objective function with the constraints.
obj= 5*x1+6*x2;
linprob = optimproblem('Objective', -obj);
linprob.Constraints.cons1 = x1+x2<=10;
linprob.Constraints.cons2 = -x1+x2<=-3;
linprob.Constraints.econs3 = 5*x1+4*x2<=35;
% Solve the LP problem.
[linsol,fval] = solve(linprob);
% Displays the solution as a vertical table
tableoptimvar= struct2table(linsol)
% Displays the objective function value
-fval
Optimal solution found.
tableoptimvar =
1×2 table
x1 x2
______ _____
5.2222 2.2222

ans =39.4444

*These are the value of x at which the value of the function is minimum within a given
constraints.

Optimization Methods (PCE8306) Page 6


Problem 3.Consider the following linear program:
( )





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.

x=0 7.0968 0 51.6129 ans =1.1032e+03

Optimization Methods (PCE8306) Page 7


2) Obtain the solution using the MATLAB optimvar and optimproblem functions
% Define all problem variables with the bounds.
x1 = optimvar('x1','LowerBound',0,'UpperBound',inf);
x2 = optimvar('x2','LowerBound',0,'UpperBound',inf);
x3 = optimvar('x3','LowerBound',0,'UpperBound',inf);
x4 = optimvar('x4','LowerBound',0,'UpperBound',inf);
% Create the objective function with the constraints.
obj= 6*x1+10*x2+9*x3+20*x4;
linprob = optimproblem('Objective', -obj);
linprob.Constraints.cons1 = 4*x1+9*x2+7*x3+10*x4<=600;
linprob.Constraints.cons2 = x1+x2+3*x3+8*x4<=420;
linprob.Constraints.econs3 = 30*x1+40*x2+20*x3+10*x4==800;
% Solve the LP problem.
[linsol,fval] = solve(linprob);
% Displays the solution as a vertical table
tableoptimvar= struct2table(linsol)
% Displays the objective function value
-fval
Optimal solution found.

tableoptimvar =

1×4 table

x1 x2 x3 x4

__ ______ __ ______

0 7.0968 0 51.613

ans =1.1032e+03

Optimization Methods (PCE8306) Page 8

You might also like