NewtonRhapson Bisection

Embed Size (px)

DESCRIPTION

komputasi

Citation preview

  • 5/20/2018 NewtonRhapson Bisection

    1/32

    Search method

    Single-variable with gradient:

    Newton Raphson & Bisection

    Budi Santosa

  • 5/20/2018 NewtonRhapson Bisection

    2/32

    Metoda dengan Gradient

    Menggunakan informasi gradient untuk

    mencari titik yang lebih baik

    Beberapa yang akan dipelajari: Newton

    Raphson, Bisection, Secant

  • 5/20/2018 NewtonRhapson Bisection

    3/32

    Metoda Newton Raphson

    Maksud:mencari akar suatu fungsi (Zeros of f(x)).

    Syarat:fungsi yang dicari nilai stasionernya harusmempunyai turunan kedua.

    Iterasi: dimulai dari suatu titikx1yang merupakan estimasi awal

    atau perkiraan dari titik stationer darifatau akar darif(x)=0.

    Aproksimasi linear darifpada titikx1dicari dan titikdimana aproksimasi linear sama dengan noldiambil

    sebagai titik baru untuk iterasi berikutnya. Secara formal, kalauxkadalah titik sekarang, aproksimasi

    linear darif(x)pada titikxkyang dinotasikan dengandiperoleh sbb:

    )(x;xf k~

  • 5/20/2018 NewtonRhapson Bisection

    4/32

    Pendekatan linier untuk f(x) pada titik xk:))((''

    ~kkkk xxxf)'(xf)'(x;xf

    )(''

    )('

    xx k1kk

    k

    xf

    xf

    Jika persamaan ini disamadengankan nol,maka kita akan memperoleh:

  • 5/20/2018 NewtonRhapson Bisection

    5/32

    Ilustrasi grafis: fungsi awal

    Function

    Tangent

    f(x)

  • 5/20/2018 NewtonRhapson Bisection

    6/32

    Ilustrasi grafis: iterasi 1

    Function

    Tangent

  • 5/20/2018 NewtonRhapson Bisection

    7/32

    Ilustrasi grafis: iterasi 2

    Function

    Tangent

  • 5/20/2018 NewtonRhapson Bisection

    8/32

    Ilustrasi grafis: iterasi 3

    Function

    Tangent

  • 5/20/2018 NewtonRhapson Bisection

    9/32

    Ilustrasi grafis: iterasi 4

    Function

    Tangent

    Misalkan iterasi berhentikarena syarat terminasi

    terpenuhi, maka aproksimasi dari akar f(x) adalah x5

  • 5/20/2018 NewtonRhapson Bisection

    10/32

    10

    Newton Raphson method

    Series of trial points:

    k

    k 1 k

    k

    f xx x

    f x

    x*

    f'(x)

    x

    x1

    x2x

    3

    Newton Raphson method (convergence).

  • 5/20/2018 NewtonRhapson Bisection

    11/32

    11

    Newton Raphson method

    k 1 1f x Convergence criteria:

    (i)

    (ii)

    (iii)

    k 1 k 2x x

    k 1 k 3f x f x

  • 5/20/2018 NewtonRhapson Bisection

    12/32

    12

    Newton Raphson method

    f'(x)

    xx1

    x2

    x3

    x0

    x*

    Divergence of Newton Raphson method.

  • 5/20/2018 NewtonRhapson Bisection

    13/32

    Newtons Method

    Misalkan kita punya fungsi yang ingin dicari

    solusinya:f(x)=0;

    Step 1: Berikan nilai awal x0

    Step 2:xn+1=xn-f(xn)/f(xn)

    xn=xn+1

    Step 3: isf(xn)small enough? jika tidak kembali ke

    step 2 Step 4: stop

  • 5/20/2018 NewtonRhapson Bisection

    14/32

    Solution Methods (2)Numerical

    Approaches:(i) Numerical Solution to Optimality Condition

    Example: Determine theminimum of

    f(x)=(10x3+3x2+x+5)2

    The optimality criteria leads:2(10x3+3x2+x+5)(30x2+6x+1)

    =0

    Problem: What is the root ofthe above equation?

  • 5/20/2018 NewtonRhapson Bisection

    15/32

    Newtons Method (example)

    MATLAB code

    x0=10;fx=100;iter=0;ff=[];xx=[];

    while abs(fx)>1.e-5

    fx=2*(10*x0^3+3*x0^2+5)*(30*x0^2+6*x0+1);

    ff=[ff;fx];fxp=2*((30*x0^2+6*x0+1)*(30*x0^2+6*x0+1)+(10*x0^3+3*x0^2+5)*(60*

    x0+6));x0=x0-fx/fxp;

    xx=[xx;x0];

    iter=iter+1;

    end

    fx = -1.6983e-006

    iter = 53

    x0 = -0.9073

  • 5/20/2018 NewtonRhapson Bisection

    16/32

    Metoda Bisection/Bolzano search

    Jika suatu fungsi adalah unimodal pada interval tertentu,maka titik-titik dimanaf(x)=0adalah titik optimalnya.

    Jika nilai fungsi bisa dihitung dan turunan pertamanyatersedia, maka metoda dengan menggunakan eliminasidaerah tertentu dengan menggunakan satu titik, akan lebihefisien untuk mencari titik dimanaf(x)=0.

    Misalkan pada titik z , f(z)

  • 5/20/2018 NewtonRhapson Bisection

    17/32

    Bisection

    Ambil dua titik Ldan Rdimanaf(L)0. Titikstasioner akan terletak antara Ldan R.

    Jika f(z) > 0 maka daerah (z,R) dieliminasi. Sebaliknya jika f(z)< 0, maka daerah (L,z) dieliminasi.

    Untuk interval a x b dan kriteria terminasi , langkah-langkah algoritma bisection bisa dijelaskan sebagai berikut: Tetapkan R = b, L= a; asumsikan bahwa f(a) < 0 dan f(b) > 0

    Hitung z = (R+L)/2 dan evaluasi f(z)

    Jika |f(z)| , stop.

    Untuk kondisi yang lain jika f(z) < 0, L=z dan ke step 2.

    Jika f(z) > 0, R = z dan ke step 2.

    Catatan: Metoda ini hanya mempertimbangkan tanda dari turunanbukan nilai dari turunan.

  • 5/20/2018 NewtonRhapson Bisection

    18/32

    A Numerical Differentiation Approach

    Problem: Find df/dx at a point xk

    Approach:

    Define xk

    Find f(xk)

    Find f(xk+xk)

    Approximate df/dx=[(f(xk+xk)- f(xk))/ xk]

  • 5/20/2018 NewtonRhapson Bisection

    19/32

    A Numerical Differentiation Approach-

    MATLAB code

    x0=10;fx=100;iter=0;ff=[];xx=[];dx=0.001;

    while abs(fx)>1.e-5

    fx=2*(10*x0^3+3*x0^2+5)*(30*x0^2+6*x0+1);

    ff=[ff;fx];

    xp=x0+dx;

    ffp=2*(10*xp^3+3*xp^2+5)*(30*xp^2+6*xp+1);

    fxp=(ffp-fx)/dx;

    x0=x0-fx/fxp;

    xx=[xx;x0];

    iter=iter+1;

    end

    fx = -4.4285e-008

    iter = 38

    x0 = -0.9073

  • 5/20/2018 NewtonRhapson Bisection

    20/32

    Remarks - Continued

    Define , N= number of experiments, or function

    evaluations.

    Let E = FR(N)

    1L

    LF N

    R

    searchgoldenfor618.0

    halvingintervalfor5.01

    2/

    N

    N

    RF

    searchgoldfor1618.0ln

    ln

    halvingintervalfor5.0ln

    ln2

    EN

    EN

    Method E=0.1 E=0.05 E=0.01 E=0.001

    I.H. 7 9 14 20

    G.S. 6 8 11 16

  • 5/20/2018 NewtonRhapson Bisection

    21/32

    METODA SECANT

    Metoda ini merupakan kombinasi dari metoda

    Newton dan region-elimination untuk menemukanakar dari persamaanf(x)=0 dalam interval (a,b) jikaada titik yang memenuhi.

    Misalkan kita ingin menemukan titik stasioner darif(x)dan mempunyai dua titik L dan R dalam interval

    (a,b) dimana turunannya mempunyai tanda yangberlawanan.

    Metoda secant mendekati turunan fungsif(x)sebagai garis secant(garis lurus yangmenghubungkan dua titik tersebut) dan menentukan

    titik berikutnya dimana garis secant dari f(x)=0. Sehingga titik berikutnya untuk mencapai titik

    stasioner x* diberikan oleh

  • 5/20/2018 NewtonRhapson Bisection

    22/32

    Jika |f(z)| ,stop. Sebaliknya, kita pilih zdan

    satu titik Latau Rsehingga tanda dariturunannya berlawanan tanda.

    Jikaf(z)0, eliminasi [z,R], R=z.

    )]/())(')('[(

    )('

    z LRLfRf

    Rf

    R

  • 5/20/2018 NewtonRhapson Bisection

    23/32

    L

    f(L)

    g(x)

    f(R)

    x*

    z

    f(x)

    R

    Garis

    secant

    x

  • 5/20/2018 NewtonRhapson Bisection

    24/32

    (iii) Polynomial Approximation Methods Powells

    Method

    Powells method is to approximate an objective

    function by a quadratic function such as

    f(x)=ax2+bx+c, then it can be shown the optimum

    is located atx*=-b/2a. Given the above equation we need to do three

    experiments (function calls) to fit a quadratic

    function, let the three experiments (function calls)located at:f(x1),f(x2), f(x3)and lets rewrite the

    quadratic equation based on the new notation:

    212110 xxxxaxxaaxq

  • 5/20/2018 NewtonRhapson Bisection

    25/32

    Powells Method- Continued

    The parameters in the previous slide can be

    found using three experiments:

    At the optimum point, it can be derived basedon the above three experiments, such that

    12

    12

    13

    13

    23

    1223132131033

    12

    121121022

    011

    1

    xx

    ff

    xx

    ff

    xxaxxxxaxxaafxf

    xxffaxxaafxf

    afxf

    12221 **0 xxaxxaadx

    dq or

    2

    112

    22*

    a

    axx

    x

  • 5/20/2018 NewtonRhapson Bisection

    26/32

    Step 1: Givenx0, x, x1=x0+x, ,

    Step 2: Evaluatef(x0),f(x1)

    Iff(x1)>f(x0), thenx2=x0-x

    Iff(x1)

  • 5/20/2018 NewtonRhapson Bisection

    27/32

    Powells MethodMATLAB code

    function alopt=one_dim_pw(xx,s,op2_func) dela=0.005;

    alp0=0.01;

    alpha(1)=alp0;alpha(2)=alpha(1)+dela;

    al=alpha(1);x1=xx+al*s;

    y(1)=feval(op2_func,x1);

    al=alpha(2);x2=xx+s*alpha(2); y(2)=feval(op2_func,x2);

    if(y(2)>=y(1)) alpha(3)=alpha(1)-dela;

    else alpha(3)=alpha(1)+2*dela;

    end

    eps=100;

    delta=100;

    while eps>0.001|delta>0.001 x3=xx+s*alpha(3);

    y(3)=feval(op2_func,x3);

    fmin=min(y);

  • 5/20/2018 NewtonRhapson Bisection

    28/32

    Powells MethodMATLAB code

    -Continued

    if(fmin==y(1)) almin=alpha(1);i=1; else if(fmin==y(2)) almin=alpha(2);i=2;

    else almin=alpha(3);i=3;

    end

    end

    a0=y(1);a1=(y(2)-y(1))/(alpha(2)-alpha(1));

    a2=1/(alpha(3)-alpha(2))*((y(3)-y(1))/(alpha(3)-alpha(1))-(y(2)-y(1))/(alpha(2)-alpha(1)));

    alopt=(alpha(2)+alpha(1))/2-a1/(2*a2); xxopt=xx+alopt*s;

    yopt=feval(op2_func,xxopt);

    eps=abs(fmin-yopt);

    delta=abs(alopt-almin);

    for j=1:3

    if(j~=i) alpha(1)=alpha(j);

    end

    end alpha(3)=alopt;alpha(2)=almin;

    x1=xx+s*alpha(1);x2=xx+s*alpha(2);

    y(1)=feval(op2_func,x1);y(2)=feval(op2_func,x2);

    end

  • 5/20/2018 NewtonRhapson Bisection

    29/32

    Example: Piping Design

    global fun_call

    x0=0.25;x_end=6;l=x_end-x0;

    al_opt=one_dim_pw(x0,l,'obj_piping')

    D=x0+al_opt*l fun_call

    al_opt = 0.1000 D =0.8250

    fun_call =61

  • 5/20/2018 NewtonRhapson Bisection

    30/32

    ComparisonInterval_halving (tol=1.e-6)

    l = 6.8545e-007

    b =

    0.8250

    a =

    0.8250

    iter =

    24

    fun_call =

    63

  • 5/20/2018 NewtonRhapson Bisection

    31/32

    The Importance of One-dimensional Problem - The

    Iterative Optimization Procedure - Continued

    The problem can be converted into:

    shownas(0,-1)

    atispointnewThe

    QED4

    028

    81714min222

    d

    df

    f

  • 5/20/2018 NewtonRhapson Bisection

    32/32

    The Importance of One-dimensional Problem - The

    Iterative Optimization Procedure - Continued

    Consider a objective

    function Min f(X)=

    x12+x2

    2, with an initial

    point X0=(-4,-1) and

    a direction (1,0), what

    is the optimum at this

    direction, i.e. X1=X0+*(1,0). This is a one

    -dimensional search for

    .