0% found this document useful (0 votes)
2 views21 pages

Chapter 7

Optimization Tools in EES and Matlab

Uploaded by

ahmedsalah30
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views21 pages

Chapter 7

Optimization Tools in EES and Matlab

Uploaded by

ahmedsalah30
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

CHAPTER 7:

Optimization Tools in EES and MATLAB

[ME488] Design of Thermal Systems Dr. Asad Alebrahim


[ME 488] Design of Thermal systems Dr. Asad Alebrahim

7-1 Optimization Using EES

One independent
variable

7-1 Optimization Using EES 2


[ME 488] Design of Thermal systems Dr. Asad Alebrahim

7-1 Optimization Using EES 3


[ME 488] Design of Thermal systems Dr. Asad Alebrahim

(1)

(2) (3)

(4)

7-1 Optimization Using EES 4


[ME 488] Design of Thermal systems Dr. Asad Alebrahim

(1) (2)

(3)

7-1 Optimization Using EES 5


[ME 488] Design of Thermal systems Dr. Asad Alebrahim

(1)

(2)

7-1 Optimization Using EES 6


[ME 488] Design of Thermal systems Dr. Asad Alebrahim

(1)

7-1 Optimization Using EES Example 7-1 7


[ME 488] Design of Thermal systems Dr. Asad Alebrahim

7-2 Optimization Using MATLAB


❑ Functions
o Functions accepts input arguments and return outputs arguments.
❑ Local functions

o A function can be defined locally @(x).

➢ Evaluate: 𝑦 = sin 𝑥 + cos 𝑥 − 𝑥 2 + 20

fx1=@(x) sin(x)+cos(x)-x^2+20;
yx1=fx1(2) % Evaluate fx1 at x=2

7-2 Optimization Using MATLAB 8


[ME 488] Design of Thermal systems Dr. Asad Alebrahim

❑ External functions
o A function m.file that accepts an input argument 𝑥 and
returns an output argument 𝑦 = 𝑓1(𝑥).

➢ Evaluate: 𝑦 = sin 𝑥 + cos 𝑥 − 𝑥 2 + 20


Write the following in the f1.m file:
function y=any_name(x)
y=sin(x)+cos(x)-x^2+20;
end
Save f1.m file

7-2 Optimization Using MATLAB 9


[ME 488] Design of Thermal systems Dr. Asad Alebrahim

❑ 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.

7-2 Optimization Using MATLAB 10


[ME 488] Design of Thermal systems Dr. Asad Alebrahim

❑ 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.

7-2 Optimization Using MATLAB Example 7-2 11


[ME 488] Design of Thermal systems Dr. Asad Alebrahim

❑ fmincon
fmincon finds a constrained minimum of a function of several
variables.

fmincon attempts to solve problems of the form:


minimize F(X)
subject to:
𝐴 ∗ 𝑋 ≤ 𝐵, 𝐴𝑒𝑞 ∗ 𝑋 = 𝐵𝑒𝑞 (linear constraints)
𝐶(𝑋) ≤ 0, 𝐶𝑒𝑞(𝑋) = 0 (nonlinear constraints)
𝐿𝐵 ≤ 𝑋 ≤ 𝑈𝐵 (bounds)

7-2 Optimization Using MATLAB 12


[ME 488] Design of Thermal systems Dr. Asad Alebrahim

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.

7-2 Optimization Using MATLAB Example 7-3 13


End of Chapter 7.
[ME 488] Design of Thermal systems Dr. Asad Alebrahim

Example 7-1

Use EES software to minimize the cost


𝑦 = 900 + 1100𝐷2.5 𝐿 + 320𝐷𝐿

Subject to the constraints


𝑛𝐿 = 100

𝜋𝐷 2
𝑛 = 200
4

7-1 Optimization Using EES Back 15


[ME 488] Design of Thermal systems Dr. Asad Alebrahim

Example 7-2

Use MATLAB to minimize the following function

3𝑥1 2
𝑦 𝑥1 , 𝑥2 = 2𝑥12 𝑥2 + 2 +𝑥
𝑥2 1

Using the following optimizations functions:

a) fminsearch

b) fminunc

7-2 Optimization Using MATLAB 16


[ME 488] Design of Thermal systems Dr. Asad Alebrahim

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

Use MATLAB software to minimize the cost


𝑦 = 900 + 1100𝐷2.5 𝐿 + 320𝐷𝐿

Subject to the constraints


𝑛𝐿 = 100

𝜋𝐷 2
𝑛 = 200
4

𝐷=𝑥 1
Let ቐ𝐿 = 𝑥(2)
𝑛 = 𝑥(3)
7-2 Optimization Using MATLAB 19
[ME 488] Design of Thermal systems Dr. Asad Alebrahim

7-2 Optimization Using MATLAB Back 20

You might also like