(11.) optimization and numerical differentiation

Upload: mohamed-deqsabriye

Post on 08-Jan-2016

235 views

Category:

Documents


0 download

DESCRIPTION

ond

TRANSCRIPT

  • 1

    CHE338_Lecture#09

    For reading

    Reference Chapter Page

    Chapra 13,23 351-366,653-668

    Optimization and

    Numerical differentiation

  • 2

    Objectives

    To introduce numerical optimization.

    To introduce numerical differentiation.

    To introduce matlab functions, fminbnd, fminsearch,

    diff, and gradient.

  • 3

    Optimization

    x

    f(x)

    To determine the minima and maxima of a function

  • 4

    One-dimensional optimization

    x

    f(x) Global optima

    Local optima

  • 5

    Golden-section search

    x

    f(x)

  • 6

    Parabolic interpolation

    x

    f(x) A parabolic function

    x1

    x2 x3

    )]()()[()]()()[(

    )]()([)()]()([)(

    2

    1

    12323212

    12

    2

    3232

    2

    1224

    xfxfxxxfxfxx

    xfxfxxxfxfxxxx

  • 7

    Matlab function: fminbnd

    [xmin,fval]=fminbnd(fun,x1,x2);

    To determine the minimum cost of the following bioreactor system

    [A] [B]

    = 1

    1 2

    0.6

    + 61

    0.6

    [A] [B]

    [A]

  • 8

    Matlab function: fminsearch

    [xmin,fval]=fminsearch(f,x1,x2)

    f=@(x) 2+x(1)-x(2)+2*x(1)^2+2*x(1)*x(2)+x(2)^2

    [xopt,optima]=fminsearch(f,[-0.5,0.5])

  • 9

    Matlab function: fmincon

    [xmin,fval] = fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon)

    [xopt,optima]=fmincon('mainf',[1,1],[],[],[],[],[],[2;1],'tankdesign')

    function f=mainf(x)

    mass=8000*((x(1)*pi*((x(2)/2+0.03)^2-

    (x(2)/2)^2)+2*pi*(x(2)/2+0.03)^2*0.03));

    lw=4*pi*(x(2)+0.03);

    f=4.5*mass+20*lw;

    end

    function [c,ceq]=tankdesign(x)

    c=[];

    ceq=pi*x(1)*x(2)^2/4-0.8;

    end

    To determine the dimensions of a cylindrical tank for a liquid with the

    lowest cost.

  • 10

    )(2

    )(3)(4)()(

    )(2

    )()(2)()()()(

    )()()(2)(

    )(

    )(2

    )()()()(

    2

    )()()()(

    212

    2

    2

    121

    2

    12

    21

    2

    1

    hOh

    xfxfxfxif

    hOhh

    xfxfxf

    h

    xfxfxif

    hOh

    xfxfxfxf

    hOhxf

    h

    xfxfxif

    hxf

    hxfxfxf

    iii

    iiiii

    iiii

    iii

    iiii

    Forward differentiation

    High Accuracy Differentiation

  • 11

    Forward differentiation

  • 12

    Backward differentiation

  • 13

    Centered differentiation

  • 14

    To improve derivative estimates

    Decrease the step size Use a higher-order formula Use Richardson extrapolation

    Accurate approximation

    Richardson extrapolation, uses two derivative

    estimates to compute a third.

    For centered difference approximations with O(h2). The application of this

    formula yield a new derivative estimate of O(h4).

  • 15

    Example 9.1 (Example 23.1 and 23.2)

    2.125.05.015.01.0)( 234 xxxxxf

  • 16

    For unequally spaced data

    iiiiii

    i

    iiii

    iii

    iiii

    iii

    xxxx

    xxxxf

    xxxx

    xxxxf

    xxxx

    xxxxfxf

    111

    11

    11

    11

    111

    11

    2)(

    2)(

    2)()(

    Use a second-order Lagrange interpolating polynomial

    to estimate the first derivative.

    x is the value at which you want to estimate the derivative.

    One can estimate the derivative anywhere within the range prescribed

    by three points

  • 17

    Example 9.2 (Example 23.3)

    Heat flux on the surface

    (z=0):

  • 18

    Matlab function: diff and gradient

    From the matlab help,

    diff(X), for a vector X

    [FX,FY] = gradient(F) returns the numerical gradient of the matrix F. FX corresponds to dF/dx, the differences in x

    (horizontal) direction. FY corresponds to dF/dy

    [FX,FY] = gradient(F,H), where H is a scalar, uses H as

    the spacing between points in each direction.

    f =@(x) 0.2+25*x-200*x.^2+675*x.^3-900*x.^4+400*x.^5

    From 0 to 1.