Chapter 7
Chapter 7
One independent
variable
(1)
(2) (3)
(4)
(1) (2)
(3)
(1)
(2)
(1)
fx1=@(x) sin(x)+cos(x)-x^2+20;
yx1=fx1(2) % Evaluate fx1 at x=2
❑ External functions
o A function m.file that accepts an input argument 𝑥 and
returns an output argument 𝑦 = 𝑓1(𝑥).
❑ fminsearch
fminsearch Multidimensional unconstrained nonlinear
minimization (Nelder-Mead).
X = fminsearch(FUN,X0)
starts at X0 and attempts to find a local minimizer X of the
function FUN. FUN is a function handle. FUN accepts input
X and returns a scalar function value F evaluated at X. X0 can
be a scalar, vector or matrix.
[X,FVAL]= fminsearch(...)
returns the value of the objective function, described in FUN,
at X.
❑ fminunc
fminunc finds a local minimum of a function of several variables.
X = fminunc(FUN,X0)
starts at X0 and attempts to find a local minimizer X of the
function FUN. FUN accepts input X and returns a scalar
function value F evaluated at X. X0 can be a scalar, vector or
matrix.
[X,FVAL] = fminunc(FUN,X0)
returns the value of the objective function, described in FUN,
at X.
❑ fmincon
fmincon finds a constrained minimum of a function of several
variables.
fmincon(FUN,X0,A,B,Aeq,Beq,LB,UB,NONLCON)
minimizes FUN while satisfying the inequality constraints, 𝐴 ∗
𝑋 ≤ 𝐵 , the equality constraints 𝐴𝑒𝑞 ∗ 𝑥 = 𝑏𝑒𝑞 and, also,
defines a set of lower and upper bounds on the design variables,
X, so that the solution is in the range 𝐿𝐵 ≤ 𝑋 ≤ 𝑈𝐵.
Also, it subjects the minimization to the constraints defined in
NONLCON. The function NONLCON accepts X and returns
the vectors C and Ceq, representing the nonlinear inequalities
and equalities respectively. fmincon minimizes FUN such that
C(X) ≤ 0 and Ceq(X) = 0. (Set an empty matrix, [], for any non-
existing constraint or bound.)
[X,FVAL] = fmincon(FUN,X0,...)
returns the value of the objective function FUN at the solution
X.
Example 7-1
𝜋𝐷 2
𝑛 = 200
4
Example 7-2
3𝑥1 2
𝑦 𝑥1 , 𝑥2 = 2𝑥12 𝑥2 + 2 +𝑥
𝑥2 1
a) fminsearch
b) fminunc
a) fminsearch
17
[ME 488] Design of Thermal systems Dr. Asad Alebrahim
b) fminunc
Back 18
[ME 488] Design of Thermal systems Dr. Asad Alebrahim
Example 7-3
𝜋𝐷 2
𝑛 = 200
4
𝐷=𝑥 1
Let ቐ𝐿 = 𝑥(2)
𝑛 = 𝑥(3)
7-2 Optimization Using MATLAB 19
[ME 488] Design of Thermal systems Dr. Asad Alebrahim