egm6341_sol_hw_03

Upload: raminshamshiri

Post on 04-Apr-2018

213 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/30/2019 EGM6341_Sol_HW_03

    1/23

    Ramin Shamshiri EGM6341, HW #3 Due 05/2/09

    Homework #3

    Due 05/2/09

    2- Write a program implementing the algorithm Bisect given in section 2.1. Use the program to calculate

    the real roots of the following equations. Use an error tolerance of =10-5

    a. 32 = 0

    b. 3

    = 2

    + + 1c. =

    1

    0.1+2

    d. = 1 + 0.3cos ()

    Solution (a)

    Root1= -0.45897

    Root2= 3.733080864

    Initial Guess

    a=4, b=-4 a=4,b=-10 1.5

    -2 2.75-1 3.375-0.5 3.6875-0.25 3.84375-0.375 3.765625-0.4375 3.7265625-0.46875 3.74609375-0.453125 3.736328125-0.4609375 3.7314453125-0.45703125 3.73388671875-0.458984375 3.732666015625-0.4580078125 3.7332763671875-0.45849609375 3.73297119140625-0.458740234375 3.73312377929688-0.4588623046875 3.73304748535156-0.45892333984375

    3.73308563232422-0.458953857421875 3.73306655883789-0.458969116210938 3.73307609558105

    3.73308086395264

    Solution (b)

    Root= 1.83927917480469

    Initial Guess

    a=2, b=-2

    0

    11.5

    1.75

    1.875

    1.8125

    1.84375

    1.828125

    1.8359375

    1.83984375

    1.837890625

    1.8388671875

    1.83935546875

    1.839111328125

    1.8392333984375

    1.839294433593751.83926391601563

    1.83927917480469

    Solution (c)

    Root=

    0.64971923828125

    Initial Guess

    a=1, b=-1

    00.5

    0.75

    0.625

    0.6875

    0.65625

    0.640625

    0.6484375

    0.65234375

    0.650390625

    0.6494140625

    0.64990234375

    0.649658203125

    0.6497802734375

    0.64971923828125

    Solution (d)

    Root= 1.1298828125

    Initial Guess

    a=2, b=1

    0.5

    1.25

    0.875

    1.0625

    1.15625

    1.109375

    1.1328125

    1.12109375

    1.126953125

    1.1298828125

  • 7/30/2019 EGM6341_Sol_HW_03

    2/23

    Ramin Shamshiri EGM6341, HW #3 Due 05/2/09

    4- Implement the algorithm Newton given in section 2.2. Use it to solve the equations in problem 2.

    Solution (a)

    Root1= -0.458962274194841

    Root2= 0.910007572548888

    Root3=3.7330790654949

    =

    Initial Guess X0=0 Initial Guess X0=1

    -1 0.914155281832543

    -0.586656659702033 0.910017665783406

    -0.469801907724523 0.910007572548888

    -0.459053916955023

    -0.458962274194841

    Initial Guess X0=3

    6.31543546409326

    5.47414948273021

    4.751646063932224.20113467567426

    3.8687230259069

    3.74791688762659

    3.73327895349399

    3.7330790654949

    Solution (b)

    Root=

    1.83928676250499

    = + +

    Initial Guess

    X0=0

    -1

    -0.5

    0.666666666666667

    -1.14814814814815

    -0.637079608343976

    0.0516071519600516

    -0.910874140183681

    -0.405089904362404

    2.3240180836761.96143817945071

    1.85002218085057

    1.83938071768498

    1.83928676250499

    Solution (c)

    Root=

    0.64975084244802

    =

    . +

    Initial Guess

    X0=00.763832077797239

    0.665436995401239

    0.650088831737976

    0.64975084244802

    Solution (d)

    Root= 1.1284251543001

    = + . ()

    Initial Guess

    X0=0

    1.3

    1.12952765547397

    1.1284251543001

  • 7/30/2019 EGM6341_Sol_HW_03

    3/23

    Ramin Shamshiri EGM6341, HW #3 Due 05/2/09

    9- Use the secant method to solve the equations given in problem 2.

    Solution (a)

    Root1= 0.910007571538623

    Root2= -0.458962267538054

    Root2=3.73307902863279

    = Initial Guess

    X0=1, X1=1 X0=4, X1=0

    0.780202717105698 -0.714521757423027

    0.902866735744908 -0.349878802434762

    0.910623538896086 -0.439082896657181

    0.910004960093375 -0.460866176241738

    0.910007571538623 -0.458931851237079

    0.780202717105698 -0.458962221693513

    0.902866735744908 -0.458962267538054

    0.910623538896086

    0.910004960093375

    0.910007571538623

    X0=3, X1=4

    3.51170436247579

    3.68065825616918

    3.74559850251939

    3.73246065052258

    3.73307193240732

    3.73307903268198

    3.73307902863279

    Solution (b)

    Root=

    1.83928675488903

    =

    + +

    Initial Guess

    X0=2, X1=11.66666666666667

    2.125

    1.8014938236139

    1.83156305015595

    1.83953463989082

    1.83928516681885

    1.83928675488903

    Solution (c)

    Root=

    0.649750681680885

    =

    . +

    Initial Guess

    X0=0, X1=10.311406831047801

    0.496402289269508

    0.761987170302371

    0.625110291746252

    0.646106965788709

    0.649879522701252

    0.64975002022824

    Solution (d)

    Root=

    = + . ()

    Initial Guess

    X0=0, x1=1

    1.14244605487164

    1.128326304321

    1.12842502375615

    1.12842509299257

  • 7/30/2019 EGM6341_Sol_HW_03

    4/23

    Ramin Shamshiri EGM6341, HW #3 Due 05/2/09

    Figure 1: Computer Application for Problem 2, 4 and 9. Author Ramin Shamshiri, EGM6341, Homework #3, 5/Feb/2009

  • 7/30/2019 EGM6341_Sol_HW_03

    5/23

    Ramin Shamshiri EGM6341, HW #3 Due 05/2/09

    X0=0.25, c=0.2

    1.703125000

    0.944278717

    1.035261085

    0.979598124

    1.012489169

    0.992600476

    1.004472485

    0.997328529

    1.0016071610.999037254

    1.000578204

    0.999653278

    1.000208105

    0.999875163

    1.000074912

    0.999955056

    1.000026967

    0.999983820

    X0=0.5,c=0.5

    1.312500000

    1.161743164

    1.041356946

    1.002600964

    1.000010156

    X0=0.8, c=0.9

    0.940800000

    0.961915801

    0.973399024

    0.980612830

    0.985498534

    0.988963873

    0.991498738

    0.993393570

    0.9948324380.995937926

    0.996794832

    0.997463573

    0.997988214

    0.998401492

    0.998728089

    0.998986837

    0.999192240

    0.999355553

    0.999485564

    0.999589166

    0.999671788

    0.999737721

    0.999790363

    0.9998324090.999866003

    0.999892851

    0.999914312

    0.999931469

    0.999945188

    0.999956159

    0.999964932

    0.999971949

    0.999977561

    0.999982050

    0.999985641

    0.999988513

    0.999990811

    0.999992649

    0.9999941190.999995296

    0.999996237

    0.999996989

    0.999997591

    0.999998073

    0.999998459

    0.999998767

    0.999999013

    0.999999211

    0.999999369

    0.999999495

    0.999999596

    0.999999677

    0.999999741

    0.999999793

    0.999999834

    0.999999868

    0.999999894

    0.5,0.4

    1.350000000

    1.094150000

    0.992140894

    1.001645746

    0.999674103

    1.000065307

    0.999986944

    1.000002611

    0.999999478

    1.000000104

    X0=0.5,c=0.5

    1.3125

    1.161743

    1.0413571.002601

    1.00001

    X0=0.8,c=0.5

    1.056

    1.004792

    1.000034

    X0=0.7,c=0.5

    1.121500000

    1.023040182

    1.000802390

    1.000000966

    X0=0.9,c=0.5

    1.0145000001.000316899

    1.000000151

    X0=0.6,c=0.5

    1.208

    1.069395

    1.007391

    1.000082

  • 7/30/2019 EGM6341_Sol_HW_03

    6/23

    Ramin Shamshiri EGM6341, HW #3 Due 05/2/09

    Prob. 24.a

    =2, P=1, c=2

    x error

    1.5 0.5

    1 1

    2 0

    2 0

    Prob. 24.b

    =1.44225, P=2, c=1

    x error

    3 1.55775043

    2.111111 0.66886154

    1.631784 0.18953457

    1.463412 0.02116242

    1.442554 0.00030455

    1.44225 6.4294E-08

    1.44225 2.8866E-15

    1.44225 0

    1.44225 0

    1.44225 0

    1.44225 0

    1.44225 0

    Prob. 24.c

    =3, P=1, c=0.75x error

    2.5 0.5

    3.428571 0.42857143

    2.709677 0.290322583.234783 0.234782612.833676 0.16632444

    3.130155 0.13015533

    2.90546 0.094540273.072622 0.07262162

    2.946505 0.053494993.040665 0.04066509

    2.969808 0.030191883.022816 0.02281612

    2.982985 0.01701504

    3.012816 0.01281579

    2.990419 0.00958115

    3.007203 0.00720311

    2.994607 0.005392623.00405 0.00404993

    2.996966 0.00303437

    3.002278 0.002277512.998293 0.00170716

    3.001281 0.00128092

    2.99904 0.00096038

    3.00072 0.00072046

    2.99946 0.00054025

  • 7/30/2019 EGM6341_Sol_HW_03

    7/23

    Ramin Shamshiri EGM6341, HW #3 Due 05/2/09

    pp.117-127 of Atkinsons textbook

    #2 Bisection method

    Solutions:

    a) f(x) = exp(x)-3x2 = 0

    Finding r1

    n x0 x1 f0 f1 x2 f2 |xn-xn-1|

    1 0 -1 1 -2.6321206 -0.5 -0.14347

    2 0 -0.5 1 -0.1434693 -0.25 0.591301 2.500E-01

    3 -0.5 -0.25 -0.1434693 0.59130078 -0.375 0.265414 1.250E-01

    4 -0.5 -0.375 -0.1434693 0.26541428 -0.4375 0.07143 6.250E-02

    5 -0.5 -0.4375 -0.1434693 0.07142978 -0.46875 -0.0334 3.125E-02

    6 -0.4375 -0.46875 0.0714298 -0.0333957 -0.453125 0.019672 1.563E-02

    7 -0.46875 -0.453125 -0.0333957 0.01967188 -0.4609375 -0.0067 7.813E-03

    8 -0.453125 -0.4609375 0.0196719 -0.006698 -0.45703125 0.006528 3.906E-03

    9 -0.4609375 -0.4570313 -0.006698 0.00652786 -0.45898438 -7.5E-05 1.953E-03

    -8

    -6

    -4

    -2

    0

    2

    4

    -1 0 1 2 3 4

    f

    x

    -10

    0

    10

    20

    30

    40

    50

    -1 0 1 2 3

    exp(x)

    3*x^2

    x

  • 7/30/2019 EGM6341_Sol_HW_03

    8/23

    Ramin Shamshiri EGM6341, HW #3 Due 05/2/09

    10 -0.4570313 -0.4589844 0.0065279 -7.485E-05 -0.45800781 0.003229 9.766E-04

    11 -0.4589844 -0.4580078 -7.485E-05 0.00322907 -0.45849609 0.001578 4.883E-04

    12 -0.4589844 -0.4584961 -7.485E-05 0.00157775 -0.45874023 0.000752 2.441E-04

    13 -0.4589844 -0.4587402 -7.485E-05 0.00075161 -0.45886230 0.000338 1.221E-04

    14 -0.4589844 -0.4588623 -7.485E-05 0.00033842 -0.45892334 0.000132 6.104E-05

    15 -0.4589844 -0.4589233 -7.485E-05 0.00013179 -0.45895386 2.85E-05 3.052E-05

    16 -0.4589844 -0.4589539 -7.485E-05 2.8474E-05 -0.45896912 -2.3E-05 1.526E-05

    17 -0.4589539 -0.4589691 2.847E-05 -2.319E-05 -0.45896149 2.64E-06 7.629E-06

    Finding r2

    n x0 x1 f0 f1 x2 f2 |xn-xn-1|

    1 0 1 1 -0.2817182 0.5 0.898721

    2 1 0.5 -0.2817182 0.89872127 0.75 0.4295 2.500E-01

    3 1 0.75 -0.2817182 0.42950002 0.875 0.102 1.250E-01

    4 1 0.875 -0.2817182 0.10200029 0.9375 -0.08313 6.250E-02

    5 0.875 0.9375 0.1020003 -0.0831293 0.90625 0.011157 3.125E-02

    6 0.9375 0.90625 -0.0831293 0.01115658 0.921875 -0.03556 1.563E-02

    7 0.90625 0.921875 0.0111566 -0.0355608 0.9140625 -0.0121 7.813E-03

    8 0.90625 0.9140625 0.0111566 -0.0120951 0.91015625 -0.00044 3.906E-03

    9 0.90625 0.91015625 0.0111566 -0.0004425 0.908203125 0.005364 1.953E-03

    10 0.9101563 0.90820313 -0.0004425 0.00536378 0.909179688 0.002462 9.766E-04

    11 0.9101563 0.90917969 -0.0004425 0.00246234 0.909667969 0.00101 4.883E-04

    12 0.9101563 0.90966797 -0.0004425 0.00101036 0.909912109 0.000284 2.441E-04

    13 0.9101563 0.90991211 -0.0004425 0.00028405 0.91003418 -7.9E-05 1.221E-04

    14 0.9099121 0.91003418 0.0002841 -7.918E-05 0.909973145 0.000102 6.104E-05

    15 0.9100342 0.90997314 -7.918E-05 0.00010245 0.910003662 1.16E-05 3.052E-05

  • 7/30/2019 EGM6341_Sol_HW_03

    9/23

    Ramin Shamshiri EGM6341, HW #3 Due 05/2/09

    16 0.9100342 0.91000366 -7.918E-05 1.1636E-05 0.910018921 -3.4E-05 1.526E-05

    17 0.9100037 0.91001892 1.164E-05 -3.377E-05 0.910011292 -1.1E-05 7.629E-06

    Finding r3

    n x0 x1 f0 f1 x2 f2 |xn-xn-1|

    1 1 4 -0.2817182 6.59815003 2.5 -6.56751

    2 4 2.5 6.59815 -6.567506 3.25 -5.89716 7.500E-01

    3 4 3.25 6.59815 -5.8971601 3.625 -1.89715 3.750E-01

    4 4 3.625 6.59815 -1.8971518 3.8125 1.657987 1.875E-01

    5 3.625 3.8125 -1.8971518 1.65798743 3.71875 -0.27446 9.375E-02

    6 3.8125 3.71875 1.6579874 -0.2744588 3.765625 0.650897 4.688E-02

    7 3.71875 3.765625 -0.2744588 0.65089669 3.7421875 0.178278 2.344E-02

    8 3.71875 3.7421875 -0.2744588 0.17827846 3.73046875 -0.05054 1.172E-02

    9 3.7421875 3.73046875 0.1782785 -0.0505415 3.736328125 0.063251 5.859E-03

    10 3.7304688 3.73632813 -0.0505415 0.06325148 3.733398438 0.006201 2.930E-03

    11 3.7304688 3.73339844 -0.0505415 0.00620129 3.731933594 -0.02221 1.465E-03

    12 3.7333984 3.73193359 0.0062013 -0.0222085 3.732666016 -0.00801 7.324E-04

    13 3.7333984 3.73266602 0.0062013 -0.0080132 3.733032227 -0.00091 3.662E-04

    14 3.7333984 3.73303223 0.0062013 -0.0009083 3.733215332 0.002646 1.831E-04

    15 3.7330322 3.73321533 -0.0009083 0.00264587 3.733123779 0.000869 9.155E-05

    16 3.7330322 3.73312378 -0.0009083 0.00086861 3.733078003 -2E-05 4.578E-05

    17 3.7331238 3.733078 0.0008686 -1.991E-05 3.733100891 0.000424 2.289E-05

    18 3.733078 3.73310089 -1.991E-05 0.00042434 3.733089447 0.000202 1.144E-05

    19 3.733078 3.73308945 -1.991E-05 0.00020221 3.733083725 9.12E-05 5.722E-06

    Need 16, 16 & 19 iterations for the error |xn-xn-1| to reach below tolerance 0.00001 for the three roots.

  • 7/30/2019 EGM6341_Sol_HW_03

    10/23

    Ramin Shamshiri EGM6341, HW #3 Due 05/2/09

    b) f(x) = x3 - x2 x -1 = 0

    n x0 x1 f0 f1 x2 f2 |xn-xn-1|

    1 2 -1 1 -2 0.5 -1.625

    2 2 0.5 1 -1.625 1.25 -1.85938 7.500E-01

    3 2 1.25 1 -1.85938 1.625 -0.97461 3.750E-01

    4 2 1.625 1 -0.97461 1.8125 -0.14331 1.875E-01

    5 2 1.8125 1 -0.14331 1.90625 0.386871 9.375E-02

    6 1.8125 1.90625 -0.14331 0.386871 1.859375 0.111721 4.688E-02

    7 1.8125 1.859375 -0.14331 0.111721 1.8359375 -0.01827 2.344E-02

    8 1.859375 1.835938 0.111721 -0.01827 1.8476563 0.046101 1.172E-02

    9 1.835938 1.847656 -0.01827 0.046101 1.8417969 0.01376 5.859E-03

    10 1.835938 1.841797 -0.01827 0.01376 1.8388672 -0.00229 2.930E-03

    11 1.841797 1.838867 0.01376 -0.00229 1.840332 0.005723 1.465E-03

    12 1.838867 1.840332 -0.00229 0.005723 1.8395996 0.001712 7.324E-04

    13 1.838867 1.8396 -0.00229 0.001712 1.8392334 -0.00029 3.662E-04

    14 1.8396 1.839233 0.001712 -0.00029 1.8394165 0.00071 1.831E-04

    y

    -10

    -5

    0

    5

    10

    -2 -1 0 1 2 3

    y

    x

  • 7/30/2019 EGM6341_Sol_HW_03

    11/23

    Ramin Shamshiri EGM6341, HW #3 Due 05/2/09

    15 1.839233 1.839417 -0.00029 0.00071 1.839325 0.000209 9.155E-05

    16 1.839233 1.839325 -0.00029 0.000209 1.8392792 -4.1E-05 4.578E-05

    17 1.839325 1.839279 0.000209 -4.1E-05 1.8393021 8.37E-05 2.289E-05

    18 1.839279 1.839302 -4.1E-05 8.37E-05 1.8392906 2.11E-05 1.144E-05

    19 1.839279 1.839291 -4.1E-05 2.11E-05 1.8392849 -1E-05 5.722E-06

  • 7/30/2019 EGM6341_Sol_HW_03

    12/23

    Ramin Shamshiri EGM6341, HW #3 Due 05/2/09

    c) f(x)=exp(x)-1/(0.1+x2)

    n x0 x1 f0 f1 x2 f2 |xn-xn-1|

    1 0 1 -9 1.809191 0.5 -1.20842

    2 1 0.5 1.809191 -1.20842 0.75 0.607566 2.500E-01

    3 0.5 0.75 -1.20842 0.607566 0.625 -0.16997 1.250E-01

    4 0.75 0.625 0.607566 -0.16997 0.6875 0.242489 6.250E-02

    5 0.625 0.6875 -0.16997 0.242489 0.65625 0.043119 3.125E-02

    6 0.625 0.65625 -0.16997 0.043119 0.640625 -0.06158 1.563E-02

    7 0.65625 0.640625 0.043119 -0.06158 0.648438 -0.00879 7.813E-03

    8 0.65625 0.648438 0.043119 -0.00879 0.652344 0.017276 3.906E-03

    9 0.648438 0.652344 -0.00879 0.017276 0.650391 0.004272 1.953E-03

    10 0.648438 0.650391 -0.00879 0.004272 0.649414 -0.00225 9.766E-04

    11 0.650391 0.649414 0.004272 -0.00225 0.649902 0.001013 4.883E-04

    12 0.649414 0.649902 -0.00225 0.001013 0.649658 -0.00062 2.441E-04

    13 0.649902 0.649658 0.001013 -0.00062 0.64978 0.000198 1.221E-04

    14 0.649658 0.64978 -0.00062 0.000198 0.649719 -0.00021 6.104E-05

    15 0.64978 0.649719 0.000198 -0.00021 0.64975 -6.2E-06 3.052E-05

    16 0.64978 0.64975 0.000198 -6.2E-06 0.649765 9.58E-05 1.526E-05

    17 0.64975 0.649765 -6.2E-06 9.58E-05 0.649757 4.48E-05 7.629E-06

    y

    -10

    -6

    -2

    2

    6

    -3 -2 -1 0 1 2

    y

    x

  • 7/30/2019 EGM6341_Sol_HW_03

    13/23

    Ramin Shamshiri EGM6341, HW #3 Due 05/2/09

    d) f(x)=x-1-0.3cos(x)

    n x0 x1 f0 f1 x2 f2 |xn-xn-1|

    1 0 2 -1.3 1.124844 1 -0.16209

    2 2 1 1.124844 -0.16209 1.5 0.478779 5.000E-01

    3 1 1.5 -0.16209 0.478779 1.25 0.155403 2.500E-01

    4 1 1.25 -0.16209 0.155403 1.125 -0.00435 1.250E-01

    5 1.25 1.125 0.155403 -0.00435 1.1875 0.075306 6.250E-02

    6 1.125 1.1875 -0.00435 0.075306 1.15625 0.035418 3.125E-02

    7 1.125 1.15625 -0.00435 0.035418 1.140625 0.015517 1.563E-02

    8 1.125 1.140625 -0.00435 0.015517 1.1328125 0.005578 7.813E-03

    9 1.125 1.132813 -0.00435 0.005578 1.12890625 0.000612 3.906E-03

    10 1.125 1.128906 -0.00435 0.000612 1.12695313 -0.00187 1.953E-03

    11 1.128906 1.126953 0.000612 -0.00187 1.12792969 -0.00063 9.766E-04

    12 1.128906 1.12793 0.000612 -0.00063 1.12841797 -9.1E-06 4.883E-04

    13 1.128906 1.128418 0.000612 -9.1E-06 1.12866211 0.000301 2.441E-04

    14 1.128418 1.128662 -9.1E-06 0.000301 1.12854004 0.000146 1.221E-04

    15 1.128418 1.12854 -9.1E-06 0.000146 1.12847900 6.85E-05 6.104E-05

    16 1.128418 1.128479 -9.1E-06 6.85E-05 1.12844849 2.97E-05 3.052E-05

    17 1.128418 1.128448 -9.1E-06 2.97E-05 1.12843323 1.03E-05 1.526E-05

    18 1.128418 1.128433 -9.1E-06 1.03E-05 1.12842560 6.42E-07 7.629E-06

    y

    -3

    -2

    -1

    0

    1

    2

    -2 -1.5 -1 -0.5 0 0.5 1 1.5 2

    y

    x

  • 7/30/2019 EGM6341_Sol_HW_03

    14/23

    Ramin Shamshiri EGM6341, HW #3 Due 05/2/09

    #4 Newtons method

    Solutions:

    a) f(x) = exp(x)-3x2

    = 0

    Finding r1

    n r1 |xn-xn-1|

    0 -1

    1 -0.58665666 0.4133433

    2 -0.469801908 0.1168548

    3 -0.459053917 0.010748

    4 -0.458962274 9.164E-05

    5 -0.458962268 6.658E-09

    Finding r2

    n xn |xn-xn-1|

    0 2

    1 1 1

    2 0.91415528 0.085844718

    3 0.91001767 0.004137616

    4 0.91000757 1.00932E-05

    5 0.91000757 6.0179E-11

    Finding r3

    n xn |xn-xn-1|

    0 3

  • 7/30/2019 EGM6341_Sol_HW_03

    15/23

    Ramin Shamshiri EGM6341, HW #3 Due 05/2/09

    1 6.315435464 3.315435

    2 5.474149483 8.413E-01

    3 4.751646064 7.225E-01

    4 4.201134676 5.505E-01

    5 3.868723026 3.324E-01

    6 3.747916888 1.208E-01

    7 3.733278953 1.464E-02

    8 3.733079065 1.999E-04

    9 3.733079029 3.686E-08

    b) f(x) = x3

    - x2 x -1 = 0

    n xn |xn-xn-1|

    0 3

    1 2.3 0.7

    2 1.95170399 3.483E-01

    3 1.84847377 1.032E-01

    4 1.83935569 9.118E-03

    5 1.83928676 6.894E-05

    6 1.83928676 3.925E-09

    c) f(x)=exp(x)-1/(0.1+x2)

    n xn |xn-xn-1|

    0 1

    1 0.58610873 0.41389127

    2 0.645119782 0.059011052

    3 0.649727346 0.004607564

    4 0.649750681 2.33349E-05

  • 7/30/2019 EGM6341_Sol_HW_03

    16/23

    Ramin Shamshiri EGM6341, HW #3 Due 05/2/09

    5 0.649750682 5.89759E-10

    d) f(x)=x-1-0.3cos(x)

    n xn |xn-xn-1|

    0 -2

    1 1.953676238 3.953676

    2 1.119933931 0.833742

    3 1.128428782 0.008495

    4 1.128425093 3.69E-06

    #9 Secant method

    Solutions:

    a) f(x) = exp(x)-3x2

    = 0

    Finding r1

    n x0 x1 x2 f0 f1 f2 error

    1 0 -1 -0.2753213 1 -2.63212 0.5319228

    2 -1 -0.27532126 -0.3971505 -2.63212 0.531923 0.1990472 1.22E-01

    3 -0.2753213 -0.39715054 -0.4699999 0.53192 0.199047 -0.037697 7.28E-02

    4 -0.3971505 -0.46999990 -0.4583999 0.19905 -0.0377 0.0019031 1.16E-02

    5 -0.4699999 -0.45839993 -0.4589574 -0.0377 0.001903 1.653E-05 5.57E-04

    6 -0.4583999 -0.45895739 -0.4589623 0.0019 1.65E-05 -7.37E-09 4.88E-06

    Finding r2

    n x0 x1 x2 f0 f1 f2 error

    1 0 1 0.78020272 1 -0.28172 0.3557657

    2 1 0.78020272 0.90286674 -0.28172 0.355766 0.0211592 1.23E-01

    3 0.78020272 0.90286674 0.91062354 0.35577 0.021159 -0.001834 7.76E-03

    4 0.90286674 0.91062354 0.91000496 0.02116 -0.00183 7.774E-06 6.19E-04

    5 0.91062354 0.91000496 0.91000757 -0.00183 7.77E-06 2.827E-09 2.61E-06

    Finding r3

  • 7/30/2019 EGM6341_Sol_HW_03

    17/23

    Ramin Shamshiri EGM6341, HW #3 Due 05/2/09

    n x0 x1 x2 f0 f1 f2 error

    1 2 4 2.82271483 -4.61094 6.59815 -7.080698

    2 4 2.82271483 3.43212293 6.59815 -7.0807 -4.396142 6.09E-01

    3 2.82271483 3.43212293 4.43006988 -7.0807 -4.39614 25.060725 9.98E-01

    4 3.43212293 4.43006988 3.58105651 -4.39614 25.06072 -2.560436 8.49E-01

    5 4.43006988 3.58105651 3.65975864 25.0607 -2.56044 -1.329536 7.87E-02

    6 3.58105651 3.65975864 3.74476739 -2.56044 -1.32954 0.2293184 8.50E-02

    7 3.65975864 3.74476739 3.73226200 -1.32954 0.229318 -0.015846 1.25E-02

    8 3.74476739 3.73226200 3.73307027 0.22932 -0.01585 -0.00017 8.08E-04

    9 3.73226200 3.73307027 3.73307904 -0.01585 -0.00017 1.282E-07 8.76E-06

    b) f(x) = x3 - x2 x -1 = 0

    n x0 x1 x2 f0 f1 f2 error

    1 3 4 2.517241379 14 43 6.096765

    2 4 2.517241 2.272275572 43 6.096765 3.296784 2.45E-01

    3 2.517241 2.272276 1.983845303 6.096765 3.296784 0.888218 2.88E-01

    4 2.272276 1.983845 1.87747957 3.296784 0.888218 0.215574 1.06E-01

    5 1.983845 1.87748 1.843390652 0.888218 0.215574 0.022526 3.41E-02

    6 1.87748 1.843391 1.839412969 0.215574 0.022526 0.000691 3.98E-03

    7 1.843391 1.839413 1.839287182 0.022526 0.000691 2.33E-06 1.26E-04

    8 1.839413 1.839287 1.839286755 0.000691 2.33E-06 2.43E-10 4.27E-07

    c) f(x)=exp(x)-1/(0.1+x2)

    n x0 x1 x2 f0 f1 f2 error

    1 1 3 0.80082071 1.809191 19.97565 0.8784118

    2 3 0.800821 0.69966549 19.97565 0.878412 0.3168178 1.01E-01

    3 0.800821 0.699665 0.64259974 0.878412 0.316818 -4.815E-02 5.71E-02

    4 0.699665 0.6426 0.6501283 0.316818 -0.04815 2.522E-03 7.53E-03

  • 7/30/2019 EGM6341_Sol_HW_03

    18/23

    Ramin Shamshiri EGM6341, HW #3 Due 05/2/09

    5 0.6426 0.650128 0.64975362 -0.04815 0.002522 1.961E-05 3.75E-04

    6 0.650128 0.649754 0.64975068 0.002522 1.96E-05 -8.016E-09 2.94E-06

    d) f(x)= x-1-0.3cos(x)

    n x0 x1 x2 f0 f1 f2 error

    1 1 3 1.1318299 -0.16209 2.296998 0.00432867

    2 3 1.13183 1.12830271 2.296998 0.004329 -0.0001556 3.53E-03

    3 1.13183 1.128303 1.12842507 0.004329 -0.00016 -2.669E-08 1.22E-04

    4 1.128303 1.128425 1.12842509 -0.00016 -2.7E-08 1.6509E-13 2.10E-08

    #13 Newtons method is the commonly used method for calculating square roots on a computer. To use

    Newtons method to calculate square root of a, an initial guess x0 must be chosen, and it would be most

    convenient to use a fixed number of iterates rather than having to test for a convergence. For definiteness,

    suppose that the computer arithmetic is binary and that the mantissa contains 48 binary bits. Write = 2 ,

  • 7/30/2019 EGM6341_Sol_HW_03

    19/23

    Ramin Shamshiri EGM6341, HW #3 Due 05/2/09

    40

    212

    80

    72

    22

    32

    1

    2

    1||

    xxx

    e

    x

    ee ,

    8041223

    160

    153

    23

    4

    2

    1

    2

    1||

    xxxx

    e

    x

    ee

    Since4

    1

    0 x ,2

    1 bxn for n>0, and

    24

    1|| 0 e , it follows that

    20

    8715164 1012.2

    )4

    1()

    2

    1(

    1

    2

    1

    24

    1||

    e < 482

    =15

    106.3

    Thus 4 iterations are definitely enough to reduce the error on the 4th

    iteration to less than machine

    epsilon.

    On the other hand, since 3x will have only half of the significant digits comparing with 4x , it is likely

    that || 3e will be on the order of )10(10

    O or a little smaller. (In reality, through trial-and-error, we

    can find that the maximum || 3e occurs at b=0.5075 with || 3e =13

    100.8

    which is higher than

    the specified tolerance). Thus 3 iterations are NOT enough to bring the error down to48

    2 level.

    Hence 4 iterations are required number of Newtons iteration.

    Improvement of x0:

    Consider 00 xbe . In order to reduce the initial error 0e , 0x should be chosen to follow

    b . The guess given by )12(3

    10 bx gives correct values at b=1/4 and 1 since )12(

    3

    10 bx is a

    linear interpolation between (b, x0) = (1/4, ) and (1, 1). To improve the initial guess, we can use a quadratic

    fit to match three points:

    (b, x0) = (1/4, ), ( , 0.70710678), and (1, 1).

    The following fit )5.0)(25.0(0.32352092)25.0(50.828427125.00 bbbx

    match those three points exactly.

  • 7/30/2019 EGM6341_Sol_HW_03

    20/23

    Ramin Shamshiri EGM6341, HW #3 Due 05/2/09

    Of course, you can use different points such as (b, x0) = (1/4, ), (5/8, 0.790569415), and (1, 1) to improve the

    initial guess.

    #21 Solution:

    a) For x = x + c f(x) = g(x) to converge

    we need |g(x)| =|1 + c f(x)|

  • 7/30/2019 EGM6341_Sol_HW_03

    21/23

    Ramin Shamshiri EGM6341, HW #3 Due 05/2/09

    Solution:

    First we observe from the given iteration that

    3( ) 2 (1 )g x c x cx

    Thus the first order derivative of g(x) is:

    2'( ) (1 ) 3g x c cx

    Since the iteration converges to =1, the derivative at the root is

    '( ) (1 ) 3 1 2g c c c

    Convergence requires | '( ) | 1g so that

    1 1 2 1c

    Thus 0 1c

    In order to obtain quadratic convergence, we need '( ) 0g which requires

    1 2 0c

    so that c= .

    #24 Solution:

    a) g(x) = -16 + 6x + 12/x, r=2

    g(x) = 6-12/x2

    => g(2) = 6-12/4=3>1 => will NOT converge.

    b)2

    1

    3

    2)(

    xxxg , r =31/3

    g(x) = 2/3 2/x3

    => g(31/3

    ) = 2/3- 2/3 = 0 will CONVERGE.

    Furthermore, because g(r)=0, it will converge quadratically (p=2).

  • 7/30/2019 EGM6341_Sol_HW_03

    22/23

    Ramin Shamshiri EGM6341, HW #3 Due 05/2/09

    c) g(x) = 12/(1+x) r=3

    g(x) = -12/(1+x)2 => g(3) = -12/16=-0.75. => will converge.

    Rate of convergence near root is=| g(3)| = 0.75.

    Since g(r)0 (which is a reasonable thing to assume for finding square root), we can see that

    from (1),

    1x > 0.

    Assume it is true for kx (i.e. kx > 0), then 1kx > 0 follows from (1).

    Second, since

    ax

    axa

    ax

    axxax

    n

    n

    n

    nnn

    2

    3

    2

    2

    13

    )(

    3

    )3((2)

    if ax 0 , then ax 1 based on (2). Hence axn using induction.

    If ax 0 then ax 1 based on (2). Hence axn using induction.

    Third, since

    ax

    xaxxx

    n

    nnnn

    2

    2

    13

    )(2we get

    nn xxa 1 if ax 0 ,

    axx nn 1 if ax 0 .

    Thus the limit of nx exists.

  • 7/30/2019 EGM6341_Sol_HW_03

    23/23

    Forth, to find the limit (assumed to be L) we get

    aL

    aLLL

    2

    2

    3

    )3(

    It can be easily found that L= a .

    b. (2) =>

    ax

    ee

    n

    nn

    2

    3

    13

    =>

    axe

    e

    nn

    n

    23

    1

    3

    1

    In the limit n becomes large, axn so thatae

    e

    n

    n

    4

    1

    3

    1

    . Thus the order of convergence is 3.

    #39 Solution:

    Results of the Newtons method using single precision:

    n zn f(zn)

    1 (2.462611, 4.645821) (2.810165, -0.9090271)

    2 (2.470614, 4.640501) (4.7531128E-03, 1.1505127E-02)

    3 (2.470639, 4.640533) (-7.6293945E-05, 4.5776367E-05)

    4 (2.470639, 4.640533) (1.2969971E-04, 4.5776367E-05)