100% found this document useful (1 vote)
146 views19 pages

Optimization With Matlab

The training covers topics related to linear programming and constraint optimization using MATLAB. It includes introductions to MATLAB, creating functions in MATLAB, and using the optimization solver FMINCON to solve problems with linear inequality constraints, linear equality constraints, and nonlinear constraints with boundaries. An example problem involving determining the optimal quantities of two types of compounds to purchase given cost and dietary constraints is provided to illustrate the analytical and numerical MATLAB approaches.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
146 views19 pages

Optimization With Matlab

The training covers topics related to linear programming and constraint optimization using MATLAB. It includes introductions to MATLAB, creating functions in MATLAB, and using the optimization solver FMINCON to solve problems with linear inequality constraints, linear equality constraints, and nonlinear constraints with boundaries. An example problem involving determining the optimal quantities of two types of compounds to purchase given cost and dietary constraints is provided to illustrate the analytical and numerical MATLAB approaches.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 19

LINEAR

PROGRAMMING ENGR. FRANCIS ALMIA

USING
DEPARTMENT OF MECHANICAL
ENGINEERING
[email protected]

OPTIMIZATION July 13-14, 2021 9:00-12:00 ; 1:00-4:00


TRAINING CONTENTS

1. MATLAB INTRODUCTION
2. PARTS AND BASIC OPERATIONS OF MATLAB
3. CREATING FUNCTIONS ON MATLAB
4. LINEAR INEQUALITY CONSTRAINT OPTIMIZATION (FMINCON)
A. ANALYTICAL APPROACH
B. MATLAB APPROACH
5. LINEAR EQUALITY CONSTRAINT OPTIMIZATION (FMINCON)
A. ANALYTICAL APPROACH
B. MATLAB APPROACH
6. NONLINEAR CONSTRAINT OPTIMIZATION WITH BOUNDARIES(FMINCON)
INTRODUCING MATLAB
What is MATLAB?
MATLAB (an abbreviation of "matrix laboratory") is a proprietary 
multi-paradigm programming language and numeric computing
 environment developed by MathWorks. MATLAB allows matrix
 manipulations, plotting of functions and data, implementation of 
algorithms, creation of user interfaces, and interfacing with programs
written in other languages.

Although MATLAB is intended primarily for numeric computing, an


optional toolbox uses the MuPAD symbolic engine allowing access to 
symbolic computing abilities. An additional package, Simulink, adds
graphical multi-domain simulation and model-based design for 
dynamic and embedded systems.
CALCULATOR

MATLAB
PARTS OF MATLAB WINDOW
BASIC PARTS AND OPERATIONS OF MATLAB
• ASSIGN VARIABLES AND VALUES
• BASIC MATH OPERATIONS
• SEMICOLONS
• CREATING ARRAYS
• USE OF COMMENTS
• VECTOR INPUT
• PLOTTING
• CLEARING WORKSPACE (clear all)
• CLEARING COMMAND WINDOW (clc)
Creating FUNCTIONS with MATLAB

What is a function?
function, in mathematics, an expression, rule, or law
that defines a relationship between one variable (the
independent variable) and another variable (the
dependent variable).

Example:  𝒚=𝟑 𝒙

y then also can be expressed as f(x), the dependent variable


𝒇  ( 𝒙)=𝟑 𝒙
In MATLAB, functions used in operations must be created in a
specific manner.
Creating FUNCTIONS with MATLAB
Steps in creating functions in MATLAB.
1. Open and go to Editor Window
2. Type “function”, then space
3. “Dep_Variable = Any_Func_Name(Indep_Variable)”, then
Enter
4. Type the “Function_Equation”, then semicolon and enter
5. Type “end”

MATLAB Function
Example
Creating FUNCTIONS with MATLAB
After editing the functions, save it as a MATLAB Script File
1. Click Save or Save As Icon in the Menu Bar
2. Save it to your Working Directory

Note: It is important to save your function scripts in the same


directory of your current working/solver scripts since the
functions are selected in the same directory.
Creating FUNCTIONS with MATLAB

Practice editing these functions:

 𝟏 . 𝑺 =𝟐 𝒙𝟐 +𝟑 𝑺𝒄𝒓𝒊𝒑𝒕 𝑵𝒂𝒎𝒆 : 𝑨𝒓𝒄


 

  𝒙𝟒
𝟐 .𝒀 = +𝟐 𝒙 𝑺𝒄𝒓𝒊𝒑𝒕 𝑵𝒂𝒎𝒆 : 𝑳𝒆𝒏𝒈𝒕𝒉
 
𝟒

 𝟑 .𝑪 = 𝒚 𝒙𝟑+ 𝒚 𝑺𝒄𝒓𝒊𝒑𝒕 𝑵𝒂𝒎𝒆 : 𝑪𝒖𝒓𝒗𝒆


 
LINEAR PROGRAMMING
Sample Problem:
LINEAR INEQUALITY CONSTRAINT
ANALYTICAL APPROACH:
On a chicken farm, the poultry is
given a healthy diet to gain
weight. The chickens have to
consume a minimum of 15 units
of Substance A and another 15
units of Substance B. In the
market there are only two classes
of compounds: Type X, with a
composition of one unit of A to
five units of B, and another type,
Y, with a composition of five
units of A to one of B. The price
of Type X is $10 and Type Y, $30.
What are the quantities of each
type of compound that have to
be purchased to cover the needs
of the diet with a minimal cost?
CONSTRAINT OPTIMIZATION IN MATLAB
NUMERICAL (MATLAB) APPROACH:
FMINCON
OPTIMIZATION SOLVER
OVERVIEW
1) DESCRIBE THE SYSTEM

2) MODEL SYSTEM USING EQUATION

3) DEFINE OBJECTIVE FUNCTION (MATLAB)

4) DEFINE CONSTRAINTS (MATLAB)

5) OPTIMIZE OBJECTIVE FUNCTION GIVEN CONSTRAINTS


CONSTRAINT OPTIMIZATION IN MATLAB

FUN (function) MATLAB INPUT:

OPTIMIZED FUNCTION
function Function_Name = Script_Name(x);
Dimension = x(1)…
…Dimesion = x(n);
Function_Name = Equation;
end

OBJECTIVE FUNCTION
function Func_Obj_Name =
Obj_Script_Name(x)
Function_Name = - Main_Script_Name(x);
end
CONSTRAINT OPTIMIZATION IN MATLAB

INITIAL GUESS MATLAB INPUT:


X0 = [ x(1) x(2) x(3)];

CALL THE SOLVER:


Dimension_Sol_Name = fmincon (@Obj_Script_Name,X0,A,B,Aeq,Beq,LB,UB,@Const_Name,[])

SET OPTIMIZED MAIN FUNCTION:


Opt_Main_Function = Function_Name (Dimension_Sol_Name)

CHECK:
Opt_Sub_Function = Function_Name (Dimension_Sol_Name)
LINEAR INEQUALITY CONSTRAINT INPUT
Linear inequality constraints have the form A·x ≤ b.
When A is m-by-n, there are m constraints on a variable x with n components.
You supply the m-by-n matrix A and the m-component vector b.
Pass linear inequality constraints in the A and b arguments.
For example, suppose that you have the following linear inequalities as constraints:
LINEAR PROGRAMMING
Sample Problem:
LINEAR EQUALITY CONSTRAINT
ANALYTICAL APPROACH:
A company manufactures and
sells two models of lamps, L1 and
L2. To manufacture each lamp,
the manual work involved in
model L1 is 20 minutes and for
L2, 30 minutes. The mechanical
(machine) work involved for L1 is
20 minutes and for L2, 10
minutes. The manual work per
month is 100 hours and the
machine must be 80 hours per
month. Knowing that the profit
per unit is 15 and 10 for L1 and
L2, respectively, determine the
quantities of each lamp that
should be manufactured to obtain
the maximum benefit.
LINEAR PROGRAMMING
NONLINEAR EQUALITY AND INEQUALITY CONSTRAINT OPTIMIZATION
with BOUNDARIES
OBJECTIVE FUNCTION:  𝑭 ( 𝑿 ) = 𝒙 𝟏 𝒙 𝟒 ( 𝒙𝟏 + 𝒙 𝟐+ 𝒙 𝟑 ) + 𝒙 𝟑

NONLINEAR INEQUALITY  𝒙𝟏 𝒙𝟐 𝒙 𝟑 𝒙 𝟒 ≥ 𝟐𝟓


CONSTRAINT:

NONLINEAR EQUALITY  𝒙𝟐 𝟐 𝟐 𝟐


𝟏 + 𝒙 𝟐 + 𝒙 𝟑 + 𝒙 𝟒 = 𝟒𝟎
CONSTRAINT:

BOUNDARIES:  𝟏≤ 𝒙 𝟏 , 𝒙 𝟐 , 𝒙𝟑 , 𝒙 𝟒 ≤ 𝟓

INITIAL GUESS:  𝒙 𝟎=(𝟏, 𝟓 , 𝟓 ,𝟏)


LINEAR PROGRAMMING
NONLINEAR CONSTRAINT INPUT
CREATE INEQUALITY CONSTRAINT FUNCTION

function [c,ceq] = Const_Name(x);


c = LARGE__VALUE_INEQUALITY – SMALL_VALUE_INEQUALITY;
ceq = RIGHT_EQUATION_SIDE – LEFT_EQUATION_SIDE;
end

BOUNDARY INPUT
ASSIGN LB AND UB AS MATRIX
lb =LOWER_LIMIT*ONES(NO_OF_VARIABLES);
ub =UPPER_LIMIT*ONES(NO_OF_VARIABLES);
MATLAB OPTIMIZATION EXERCISE

LINEAR INEQUALITY CONSTRAINT


A COMPANY RECEIVES IN SALES $20 PER BOOK AND $18 PER CALCULATOR.
THE COST PER UNIT TO MANUFACTURE EACH BOOK AND CALCULATOR ARE $5
AND $4 RESPECTIVELY. THE MONTHLY (30 DAY) COST MUST NOT EXCEED
$27,000 PER MONTH. IF THE MANUFACTURING EQUIPMENT USED BY THE
COMPANY TAKES 5 MINUTES TO PRODUCE A BOOK AND 15 MINUTES TO
PRODUCE A CALCULATOR. HOW MANY BOOKS AND CALCULATORS SHOULD
THE CMOPANY MAKE TO MAXIMIZE PROFIT? DETERMINE THE MAXIMUM PROFIT
IF THE COMPANY EARNS IN A 30 DAY PERIOD.

OPTIMIZED SALES = $ 110,934

OPTIMIZED PROFIT = $ 83,934

You might also like