0% found this document useful (0 votes)
125 views

Optimization Using MATLAB

This document discusses various optimization techniques available in MATLAB, including: 1. fminbnd to find the minimum of a single-variable function on a fixed interval. 2. fminsearch to find the minimum of an unconstrained multivariable function using a derivative-free method. 3. fzero to find the root of a nonlinear function. 4. fminsearch and fminbnd to minimize functions of several variables or a single variable. 5. fmincon to minimize a function subject to linear or nonlinear equality and inequality constraints. 6. fminimax to find values that minimize the maximum value of multiple functions.

Uploaded by

jayanand b
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
0% found this document useful (0 votes)
125 views

Optimization Using MATLAB

This document discusses various optimization techniques available in MATLAB, including: 1. fminbnd to find the minimum of a single-variable function on a fixed interval. 2. fminsearch to find the minimum of an unconstrained multivariable function using a derivative-free method. 3. fzero to find the root of a nonlinear function. 4. fminsearch and fminbnd to minimize functions of several variables or a single variable. 5. fmincon to minimize a function subject to linear or nonlinear equality and inequality constraints. 6. fminimax to find values that minimize the maximum value of multiple functions.

Uploaded by

jayanand b
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/ 12

Optimization Using MATLAB

Jayanand B
Optimizing a Non-linear function

fminbnd Find minimum of single-variable


function on fixed interval
fminsearch Find minimum of unconstrained
multivariable function using derivative-
free method
fzero Root of nonlinear function
Find a zero of the function using
‘fzero’
f(x) = x3 – 2x – 5.

function y = f(x)
y = x.^3 - 2*x - 5;

fun = @f; % function


x0 = 2; % initial point
z = fzero(fun,x0)
Using fminbnd
Create a ‘humps’ function
x = -1:.01:2;
y = humps(x);
plot(x,y)
xlabel('x')
ylabel('humps(x)')
grid on
x = fminbnd(@humps,0.3,1)
Minimizing Functions of Several Variables using ‘fminsearch’

function b = three_var(v)
x = v(1); y = v(2); z = v(3);
b = x.^2 + 2.5*sin(y) - z^2*x^2*y^2;

v = [-0.6,-1.2,0.135];
a = fminsearch(@three_var,v)
Options for ‘fminbnd’
opts = optimset('Display','iter');
x = fminbnd(@humps,0.3,1,opts)
‘fmincom’
With linear inequalities:
Minimize
f(x) = 100(x2 – x12)2 + (1 – x1)2 , starting from the point [-
1,2], constrained to have x(1)+2x(2) ≤ 1
Express constraint as A*x ≤ B
fun = @(x)100*(x(2) – x(1)^2)^2 + (1 – x(1))^2;
x0 = [-1, 2];
A = [1,2];
B=1;
x = fmincon(fun,x0,A,B)
‘fmincon’
With linear inequality and equality constraints:
Minimize
f(x) = 100(x2 – x12)2 + (1 – x1)2 , starting from the point
[0.5,0], constrained to have x(1)+2x(2) ≤ 1 and 2x(1) + x(2) =
1
fun = @(x)100*(x(2) – x(1)^2)^2 + (1 – x(1))^2;
x0 = [-1, 2];
A = [1,2];B=1;
Aeq = [2,1]; Beq = 1;
x = fmincon(fun,x0,A,B,Aeq,Beq)
‘fmincon’
With nonlinear constraints:
Minimize
f(x) = 100(x2 – x12)2 + (1 – x1)2 , look in the region within
the circle centered at [1/3 1/3] and having a radius of 1/3
Create a function for nonlinear constraints :
function [c ceq] = nlconstraints(x);
c = (x(1) – 1/3)^2 + (x(2) – 1/3)^2 – (1/3)^2;
Ceq = [];
nonlin = @nlconstraints;
fun = @(x)100*(x(2) – x(1)^2)^2 + (1 – x(1))^2;
x0 = [0.25, 0.25];
A = []; B=[]; Aeq = []; Beq = [];
Lb = []; Ub = [];
x = fmincon(fun,x0,A,B,Aeq,Beq,Lb,Ub,nonlin)
‘fminimax’
Find values of x that minimize the maximum value of
[f1(x), f2(x), f3(x), f4(x), f5(x)]
where
f1(x)=2x12+x22−48x1−40x2+304,
f2(x)=−x12−3x22,
f3(x)=x1+3x2−18,
f4(x)=−x1−x2,
f5(x)=x1+x2−8.
First, write a file that computes the five functions at x.
function f = myfun(x)
f(1)= 2*x(1)^2+x(2)^2-48*x(1)-40*x(2)+304;
f(2)= -x(1)^2 - 3*x(2)^2;
f(3)= x(1) + 3*x(2) -18;
f(4)= -x(1)- x(2); f(5)= x(1) + x(2) - 8;
Next, invoke an optimization routine.
x0 = [0.1; 0.1]; % Make a starting guess at solution
[x,fval] = fminimax(@myfun,x0);

You might also like