Lectures_on_Cuves_Fitting

Embed Size (px)

Citation preview

  • 8/7/2019 Lectures_on_Cuves_Fitting

    1/36

    LECTURE - 7

  • 8/7/2019 Lectures_on_Cuves_Fitting

    2/36

    LEAST SQUARES

    CURVE FITTING

  • 8/7/2019 Lectures_on_Cuves_Fitting

    3/36

    Motivation

    Given a set of experimental data

    x 1 2 3

    y 5.1 5.9 6.3

    The relationship between x

    and y may not be clearwe want to find an

    expression for f(x)1 2 3

  • 8/7/2019 Lectures_on_Cuves_Fitting

    4/36

    KEPPLER THIRD LAW OF

    PLANETARY MOTION

  • 8/7/2019 Lectures_on_Cuves_Fitting

    5/36

  • 8/7/2019 Lectures_on_Cuves_Fitting

    6/36

    Curve Fitting

    Given a set of

    tabulated data, find acurve or a function

    that best representsthe data.

  • 8/7/2019 Lectures_on_Cuves_Fitting

    7/36

    EXPERIMENTAL ERROR

    xi x1 x2 . xn

    yi y1 y2 . yn

    Given

    The form of the function is assumed to

    be known but the coefficients are

    unknown.

    kkk eyxf!

    )(The difference is assumed to be the result of

    experimental error

  • 8/7/2019 Lectures_on_Cuves_Fitting

    8/36

    ERROR

    2

    1

    1

    2

    2

    11

    k

    k

    N

    1kk

    ))(1

    ((f)EError-RMS

    )(1)(EErrorAverage

    )(max)(EErrorMaximum

    N.k1for)(e)deviationscalled(alsoerrorcalledis

    datarecordedtheand)f(xvaluetrueebetween th

    differenceThedata.ofsetthe)}y,{(x

    !

    !

    !

    ee!

    g

    N

    kk

    N

    kk

    kk

    kk

    yxfN

    yxfN

    f

    yxff

    yxf

    beLet

  • 8/7/2019 Lectures_on_Cuves_Fitting

    9/36

    LEAST- SQUARES LINE

    INTRODUCTION

  • 8/7/2019 Lectures_on_Cuves_Fitting

    10/36

    LEAST- SQUARES LINE

    The least square liney=f(x)=Ax+B is the line

    that minimizes RMS-error

  • 8/7/2019 Lectures_on_Cuves_Fitting

    11/36

    Please write down the black boardsummary

    FINDING LEAST-SQUARES LINE

  • 8/7/2019 Lectures_on_Cuves_Fitting

    12/36

    Determine the Unknowns

    ?),(minimizetoandobtainedoHo

    )(),(

    minimizetoba,indant toWe

    0

    2

    baEba

    bxafbaEN

    k

    kk !!

  • 8/7/2019 Lectures_on_Cuves_Fitting

    13/36

    Determine the Unknowns

    ?),(minimizetoandobtainwedoow

    )(),(

    minimizetoba,findwant toWe

    0

    2

    baba

    bxafban

    i

    ii

    *

    !* !

  • 8/7/2019 Lectures_on_Cuves_Fitting

    14/36

    Determine the Unknowns

    0

    ),(

    0),(

    minimumfor theconditionNecessary

    !x

    x

    !x

    x

    b

    ba

    aba

  • 8/7/2019 Lectures_on_Cuves_Fitting

    15/36

    Remember

    !xx

    !

    !!

    !!

    n

    kk

    n

    ki

    n

    kk

    n

    kk

    xgaxga

    axadx

    d

    11

    11

    )()(

  • 8/7/2019 Lectures_on_Cuves_Fitting

    16/36

    Example 1

    !

    !

    !!x

    x

    !!x

    x

    !!!

    !!

    !

    !

    N

    kkk

    N

    kk

    N

    kk

    N

    kk

    N

    kk

    k

    N

    kkk

    N

    kkk

    yxbxax

    ybxaN

    xybxabbaE

    ybxaa

    baE

    11

    2

    1

    11

    1

    1

    EquationsNormal

    20),(

    20),(

  • 8/7/2019 Lectures_on_Cuves_Fitting

    17/36

    Example 1

    !

    !

    !!

    !!

    !!!

    N

    k

    k

    N

    k

    k

    N

    k

    k

    N

    k

    k

    N

    k

    k

    N

    k

    k

    N

    k

    kk

    xbyN

    a

    xxN

    yxyxN

    b

    11

    2

    11

    2

    111

    1

    givesEquationsNormaltheolving

  • 8/7/2019 Lectures_on_Cuves_Fitting

    18/36

    Example 1

    k 1 2 3 sum

    xk 1 2 3 6

    yk 5.1 5.9 6.3 17.3

    xk2 1 4 9 14

    xk yk 5.1 11.8 18.9 35.8

  • 8/7/2019 Lectures_on_Cuves_Fitting

    19/36

    Example 1

    60.04.5667

    8.35146

    3.1763

    EquationsNormal

    11

    2

    1

    11

    !!

    !

    !

    !

    !

    !!!

    !!

    baSolving

    ba

    ba

    yxbxax

    ybxaN

    N

    k

    kk

    N

    k

    k

    N

    k

    k

    N

    k

    k

    N

    k

    k

  • 8/7/2019 Lectures_on_Cuves_Fitting

    20/36

    Power Fit

    AxY M!

  • 8/7/2019 Lectures_on_Cuves_Fitting

    21/36

    Example 2

    data.fit theto

    )cos()ln()(

    formtheoffunctionafindtorequiredisIt

    xecxbxaxf !

    x 0.24 0.65 0.95 1.24 1.73 2.01 2.23 2.52

    y 0.23 -0.23 -1.1 -0.45 0.27 0.1 -0.29 0.24

  • 8/7/2019 Lectures_on_Cuves_Fitting

    22/36

    Example 2

    EquationsNormal

    c

    cbab

    cba

    acba

    !x

    *x

    !

    x

    *x

    !x*x

    0),,(

    0),,(

    0),,(

    minimumfor theconditionNecessary

  • 8/7/2019 Lectures_on_Cuves_Fitting

    23/36

    Example 2

    equationsnormalthesolveandsumstheEvaluate

    )()())((cos)()(ln

    )(cos)()(cos)(cos)(cos)(ln

    )(ln)()(ln)(cos)(ln)(ln

    8

    1

    8

    1

    28

    1

    8

    1

    8

    1

    8

    1

    8

    1

    28

    1

    8

    1

    8

    1

    8

    1

    28

    1

    kkkk

    k

    k

    x

    k kk

    x

    k

    x

    k

    x

    k k

    k

    kk

    x

    k

    k

    k

    kk

    k

    k

    k

    kk

    x

    k

    kk

    k

    k

    k

    k

    eyecexbexa

    xyexcxbxxa

    xyexcxxbxa

    !!!!

    !!!!

    !!!!

    !

    !

    !

  • 8/7/2019 Lectures_on_Cuves_Fitting

    24/36

    How do you judge performance?

    best?select theyoudoow

    data,fit thetofunctionsmoreorGiven two

    sense.square

    leastin thebesttheis)(smallerinresulting

    functionTheone.eachfor)(computethen

    functioneachforparameterstheDetermine

    :

    2

    2

    fE

    fE

    Answer

  • 8/7/2019 Lectures_on_Cuves_Fitting

    25/36

    Multiple Regression

    Example:

    Given the following data

    It is required to determine afunction of two variables

    f(x,t) = a + b x + c t

    to explain the data that is bestin the least square sense.

    t 0 1 2 3

    x 0.1 0.4 0.2 0.2

    f(x,t) 3 2 1 2

  • 8/7/2019 Lectures_on_Cuves_Fitting

    26/36

    SolutionofMultiple Regression

    Construct , the sumof the square of theerror and derive the

    necessary conditionsby equating thepartial derivativeswith respect to theunknown parameters

    to zero then solvethe equations.

    * t 0 1 2 3

    x 0.1 0.4 0.2 0.2

    f(x,t) 3 2 1 2

  • 8/7/2019 Lectures_on_Cuves_Fitting

    27/36

    SolutionofMultiple Regression

    02),,(

    02

    ),,(

    02),,(conditionsNecessary

    ),,(

    ),(

    4

    1

    4

    1

    4

    1

    4

    1

    2

    !!x

    *x

    !!x

    *x

    !!x

    *x

    !*

    !

    !

    !

    !

    !

    i

    i

    iii

    ii

    iii

    i

    iii

    i

    iii

    tfctbxac

    cba

    xfctbxab

    cba

    fctbxaa

    cba

    fctbxacba

    ctbxatxf

  • 8/7/2019 Lectures_on_Cuves_Fitting

    28/36

    Nonlinear least squares problems

    EXAMPLES

  • 8/7/2019 Lectures_on_Cuves_Fitting

    29/36

    data.fit thebestthatformtheoffuctionafind

    bx

    ae

    ii

    ii

    i

    bx

    i

    ibx

    bx

    i

    ibx

    i

    ibx

    ebayaeb

    eyaea

    yae

    !

    !

    !

    !!

    x

    *x

    !!

    x*x

    !*

    3

    1

    3

    1

    3

    1

    2

    0

    0

    usingobtainedareEquationsNormal

    Nonlinear Problem

    Givenx 1 2 3

    y 2.4 5. 9

  • 8/7/2019 Lectures_on_Cuves_Fitting

    30/36

    data.fit thebestthatformtheoffuctionafind

    bx

    ae

    solve)easier to(useillWe

    usingoInstead

    )ln()ln(

    bxln(a)ln(y)zDe ine

    3

    1

    2

    3

    1

    2

    !

    !

    !*

    !*

    !!

    !!

    i

    ii

    ii

    bx

    ii

    zbx

    yae

    yzandaet

    i

    E

    E

    Alternative Solution(LinearizationMethod)

    Givenx 1 2 3

    y 2.4 5. 9

  • 8/7/2019 Lectures_on_Cuves_Fitting

    31/36

    InconsistentSystem ofEquations

    solutionNo

    EquationsofsystemntinconsisteisThis

    10

    6

    4

    1.43

    2221

    equationsofsystemfollowingtheSolve

    :Problem

    2

    1

    !

    x

    x

  • 8/7/2019 Lectures_on_Cuves_Fitting

    32/36

    InconsistentSystem ofEquationsReasons

    Inconsistent equations

    may occur because of

    errors in formulatingthe problem, errors in

    collecting the data or

    computational errors.

    Solution if all lines intersect

    at one point

  • 8/7/2019 Lectures_on_Cuves_Fitting

    33/36

    InconsistentSystem ofEquationsFormulationasa leastsquares problem

    errorsquaresleasttheminimizetoandFind

    10

    6

    4

    1.43

    22

    21

    asequationsthecan viewWe

    21

    3

    2

    1

    2

    1

    xx

    x

    x

    !

    I

    I

    I

  • 8/7/2019 Lectures_on_Cuves_Fitting

    34/36

    Solution

    12262.4936.6

    )822416()62.3388()6.2484(0

    )011.43(2.86)22(44)2(40

    926.3628

    )60248()6.2484()1882(0

    )011.43(66)22(44)2(20

    minimizetoandFind

    )011.43(6)22(4)2(

    21

    21

    2121212

    21

    21

    2121211

    21

    221

    221

    221

    !

    !

    !!x*x

    !

    !

    !!x

    *x

    *

    !*

    xx

    xx

    xxxxxxx

    xx

    xx

    xxxxxxx

    xx

    xxxxxx

  • 8/7/2019 Lectures_on_Cuves_Fitting

    35/36

    Solution

    0.9799,2.0048

    :

    12262.4936.6

    926.3628

    :equationsNormal

    21

    21

    21

    !!

    !

    !

    xx

    Solution

    xx

    xx

  • 8/7/2019 Lectures_on_Cuves_Fitting

    36/36

    data.it thebestthatb)/(ax1ormtheouctionaind

    !

    !

    !*

    !*

    !

    !!

    !

    3

    1

    2

    3

    1

    2

    usewillWe

    bax

    1usingoInstead

    1

    bax1

    ze ine

    bax

    1f(x)

    i

    ii

    i

    i

    ii

    zbax

    y

    yzLet

    y

    Examples(LinearizationMethod)

    Givenx 1 2 3

    y 0.23 .2 .14