Optimization With Matlab
Optimization With Matlab
USING
DEPARTMENT OF MECHANICAL
ENGINEERING
[email protected]
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.
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: 𝒚=𝟑 𝒙
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
𝒙𝟒
𝟐 .𝒀 = +𝟐 𝒙 𝑺𝒄𝒓𝒊𝒑𝒕 𝑵𝒂𝒎𝒆 : 𝑳𝒆𝒏𝒈𝒕𝒉
𝟒
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
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: 𝑭 ( 𝑿 ) = 𝒙 𝟏 𝒙 𝟒 ( 𝒙𝟏 + 𝒙 𝟐+ 𝒙 𝟑 ) + 𝒙 𝟑
BOUNDARIES: 𝟏≤ 𝒙 𝟏 , 𝒙 𝟐 , 𝒙𝟑 , 𝒙 𝟒 ≤ 𝟓
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