You are on page 1of 11

OPTIMIZATION LAB ASSIGNMENT

DATE: 04/09/2013

Q.1. Find the solution of the following Linear Programming problem using MATLAB function linprog and Optimization Tool. a) Minimize subject to f=-x1-2x2-x3 2x1-x2+5x3<=6 2x1+x2-x3<=2 4x1+x2+x3<=6, MATLAB Code:
clc; f=[-1 -2 -1]; A=[2 -1 5;2 1 -1;4 1 1]; b=[6;2;6]; lb=[0 0 0]; [x,fval]=linprog(f,A,b,[],[],lb,[])

xi>=0 for i=1,2,3.

Result: Optimization terminated. x= 0.0000 4.0000 2.0000 fval = -10.0000

Optimization Tool:

62

Remarks: The feasible optimal solution has been obtained using MATLAB m.file code as well as optimization tool . b) Minimize subject to f=-3x1-2x2 x1-x2<=1 3x1-2x2<=6, MATLAB Code:
clear all; close all; clc; f=[-3 -2]; A=[1 -1;3 -2]; b=[1;6]; lb=[0;0]; [x,fval]=linprog(f,A,b,[],[],lb,[])

xi>=0 for i=1,2.

Result: Exiting: One or more of the residuals, duality gap, or total relative error has stalled: the dual appears to be infeasible (and the primal unbounded). (The primal residual < TolFun=1.00e-008.) x = 1.0e+014 * 3.2081 4.8121 fval = -1.9248e+015 Optimization Tool:

63

Remarks: The solution of the minimization function was unbounded. So solution is infeasible solution.

c) Minimize subject to

f=-40x1-100x2 10x1+5x2<=2500 4x1+10x2<=2000 2x1+5x2<=900, xi>=0 for i=1,2.

MATLAB Code:
clear all; close all; clc; f=[-40 -100]; A=[10 5;4 10;2 5]; b=[2500;2000;900]; lb=[0;0]; [x,fval]=linprog(f,A,b,[],[],lb,[])

64

Result: Optimization terminated. x= 186.3907 105.4437 fval = Optimization Tool: -1.8000e+004

Remarks: The solution is feasible optimal solution has been obtained.

d) Minimize subject to

f=-x1-2x2-x3 2x1+x2-x3<=2 2x1-x2+5x3<=6 4x1+x2+x3<=6, xi>=0 for i=1,2,3.

65

MATLAB Code:
clear all; close all; clc; f=[-1 -2 -1]; A=[2 1 -1;2 -1 5;4 1 1]; b=[2;6;6]; lb=[0 0 0]; [x,fval]=linprog(f,A,b,[],[],lb,[])

Result: Optimization terminated. x= 0.0000 4.0000 2.0000 fval = Optimization Tool: -10.0000

Remarks: The feasible optimal solution has been obtained. 66

OPTIMIZATION LAB ASSIGNMENT


DATE:18/09/2013

Q.2 Find the solution of the following non-linear optimization problem using the MATLAB function fmincon. Minimize Subject to f=9.82x1x2+2x2 g1=2500/x1x2-500<=0; g2=2500/x1x2-((x12+x22)/0.5882)<=0; g3=-x1+2<=0; g4=x1-14<=0; g5=-x2+0.2<=0; g6=x2-0.8<=0; MATLAB Code : a) With Non Linear Function solver fmincon: The objective function objpara.m
function y =objpara(x) y=9.82*x(1)*x(2)+2*x(1);

xi>=0 for i=1,2.

Constraint files nonlconstr.m:


function [c,ceq]=nonlconstr(x) c=[(2500/(pi*x(1)*x(2)))-500; (2500/(pi*x(1)*x(2)))-((pi*(x(1)^2+x(2)^2))/0.5882); -x(1)+2;x(1)-14;-x(2)+0.2;x(2)-0.8]; ceq=[];

Run file Q_1.m:


clc; clear all; x0=[7 0.4]; f=objfun(x0); [c,ceq]=nonlconstr(x0); [x,fval]=fmincon(@objfun,x0,[],[],[],[],[],[],@nonlconstr) [c,ceq]=nonlconstr(x)

Result: Active inequalities (to within options.TolCon = 1e-006): x= fval = c= 9.0638 35.9287 -61.0125 67 0.2000

0.0000 -7.0638 -4.9362 0 -0.6000 ceq = []

Optimization Tool:

Remarks: The solution of non-linear optimization problem has been obtained using MATLAB function fmincon.

68

Q.3 Find the solution of the following non-linear optimization problem using the MATLAB function ga (Genetic Algorithm). Minimize Subject to f=9.82x1x2+2x2 g1=2500/x1x2-500<=0; g2=2500/x1x2-((x12+x22)/0.5882)<=0; g3=-x1+2<=0; g4=x1-14<=0; g5=-x2+0.2<=0; g6=x2-0.8<=0; xi>=0 for i=1,2.

MATLAB Code: First, create the objective function an M-file named spobf_1.m as follows:
function f=spobj_1(x) f=9.82*x(1)*x(2)+2*x(1);

Then create an M-file, simple_constraint.m, containing the constraints:


function [c,ceq]=simple_constraint(x) c=[(2500/(pi*x(1)*x(2)))-500; (2500/(pi*x(1)*x(2)))-((pi*(x(1)^2+x(2)^2))/0.5882)]; ceq=[];

To minimize the fitness function, you need to pass a function handle to the fitness function as the first argument to the ga function, as well as specifying the number of variables as the second argument. Lower and upper bounds are provided as LB and UB respectively. In addition, you also need to pass a function handle to the nonlinear constraint function.
ObjectiveFunction = @spobj_1; nvars = 3; % Number of variables LB = [2 0.2]; % Lower bound ConstraintFunction = @simple_constraint; [x,fval]=ga(ObjectiveFunction,nvars,[],[],[],[],LB,[14 0.8],ConstraintFunction)

Result: Optimization terminated: average change in the fitness value less than options.TolFun and constraint violation is less than options.TolCon. x= fval = Optimization Tool: 9.0632 35.9300 0.2000

69

Remark: The solution of the non-linear optimization problem using the MATLAB function ga (Genetic Algorithm) has been obtained.

Q.4 Find the solution of the following linear programming problem using MATLAB function ga (Genetic Algorithm). Minimize Subject to f=-x1-2x2-x3 2x1+x2-x3<=2 2x1-x2+5x3<=6 4x1+x2+x3<=6, xi>=0 for i=1,2,3.

70

MATLAB Code: The minimum objective function spobj.m


function f=spobj(x) f=-x(1)-2*x(2)-x(3);

Linear Constraints spobj_run.m file


clc; close all; clear all; a=[2 1 -1;2 -1 5;4 1 1]; b=[2;6;6]; [x,fval,exitflag]=ga(@spobj,3,a,b,[],[],[0;0;0],[])

Result: Optimization terminated: average change in the fitness value less than options.TolFun. x= fval = exitflag = 0.0087 -9.9229 1 3.9644 1.9855

Optimization Tool:

Remark: The solution of linear programming problem has been obtained using ga function. 71

OPTIMIZATION LAB ASSIGNMENT


DATE: 25/09/2013

Q.5 Find the minimum solution of the following function using MATLAB simulated annealing function. f=500-20x1-26x2-4x1x2+4x12+3x22

MATLAB Code: Objective function file spobj_4.m


function f=spobj_4(x) f=500-20*x(1)-26*x(2)-4*x(1)*x(2)+4*(x(1)^2)+3*(x(2)^2);

OptimizationTool:

Remark: The minimum value of the function using MATLAB function simulated annealing has been obtained.

72