Professional Documents
Culture Documents
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.
b.
c.
d.
3 2 = 0
3 = 2 + + 1
1
= 0.1+ 2
= 1 + 0.3cos
()
Solution (a)
Solution (b)
Solution (c)
Solution (d)
Root1= -0.45897
Root2= 3.733080864
Root= 1.83927917480469
Root=
0.64971923828125
Root= 1.1298828125
Initial Guess
a=4, b=-4
a=4,b=-1
0
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
Ramin Shamshiri
Initial Guess
a=2, b=-2
0
1
1.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.83929443359375
1.83926391601563
1.83927917480469
Initial Guess
a=1, b=-1
0
0.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
EGM6341, HW #3
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
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)
Solution (b)
Solution (c)
Solution (d)
Root1= -0.458962274194841
Root2= 0.910007572548888
Root3= 3.7330790654949
Root=
Root=
Root= 1.1284251543001
1.83928676250499
0.64975084244802
= + +
=
Initial Guess X0=0
-1
-0.586656659702033
-0.469801907724523
-0.459053916955023
-0.458962274194841
Ramin Shamshiri
Initial Guess
X0=0
-1
-0.5
0.666666666666667
-1.14814814814815
-0.637079608343976
0.0516071519600516
-0.910874140183681
-0.405089904362404
2.324018083676
1.96143817945071
1.85002218085057
1.83938071768498
1.83928676250499
=
. +
= + .
()
Initial Guess
X0=0
Initial Guess
X0=0
0.763832077797239
1.3
0.665436995401239
1.12952765547397
0.650088831737976
1.1284251543001
0.64975084244802
EGM6341, HW #3
Due 05/2/09
Solution (b)
Solution (c)
Solution (d)
Root1= 0.910007571538623
Root2= -0.458962267538054
Root2= 3.73307902863279
=
Root=
1.83928675488903
= + +
Root=
Root=
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
0.649750681680885
. +
= + .
()
Initial Guess
X0=2, X1=1
1.66666666666667
2.125
1.8014938236139
1.83156305015595
1.83953463989082
1.83928516681885
1.83928675488903
Initial Guess
X0=0, X1=1
0.311406831047801
0.496402289269508
0.761987170302371
0.625110291746252
0.646106965788709
0.649879522701252
0.64975002022824
Initial Guess
X0=0, x1=1
1.14244605487164
1.128326304321
1.12842502375615
1.12842509299257
X0=3, X1=4
3.51170436247579
3.68065825616918
3.74559850251939
3.73246065052258
3.73307193240732
3.73307903268198
3.73307902863279
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
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.001607161
0.999037254
1.000578204
0.999653278
1.000208105
0.999875163
1.000074912
0.999955056
1.000026967
0.999983820
X0=0.9,c=0.5
1.014500000
1.000316899
1.000000151
Ramin Shamshiri
X0=0.5,c=0.5
1.312500000
1.161743164
1.041356946
1.002600964
1.000010156
X0=0.7,c=0.5
1.121500000
1.023040182
1.000802390
1.000000966
X0=0.6,c=0.5
1.208
1.069395
1.007391
1.000082
X0=0.8, c=0.9
0.940800000
0.961915801
0.973399024
0.980612830
0.985498534
0.988963873
0.991498738
0.993393570
0.994832438
0.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.999832409
0.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.999994119
0.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
EGM6341, HW #3
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.041357
1.002601
1.00001
X0=0.8,c=0.5
1.056
1.004792
1.000034
Due 05/2/09
Prob. 24.a
=2, P=1, c=2
error
x
1.5
1
2
2
0.5
1
0
0
Prob. 24.b
=1.44225, P=2, c=1
x
3
2.111111
1.631784
1.463412
1.442554
1.44225
1.44225
1.44225
1.44225
1.44225
1.44225
1.44225
error
1.55775043
0.66886154
0.18953457
0.02116242
0.00030455
6.4294E-08
2.8866E-15
0
0
0
0
0
Prob. 24.c
=3, P=1, c=0.75
x
2.5
3.428571
2.709677
3.234783
2.833676
3.130155
2.90546
3.072622
2.946505
3.040665
2.969808
3.022816
2.982985
3.012816
2.990419
3.007203
2.994607
3.00405
2.996966
3.002278
2.998293
3.001281
2.99904
3.00072
2.99946
error
0.5
0.42857143
0.29032258
0.23478261
0.16632444
0.13015533
0.09454027
0.07262162
0.05349499
0.04066509
0.03019188
0.02281612
0.01701504
0.01281579
0.00958115
0.00720311
0.00539262
0.00404993
0.00303437
0.00227751
0.00170716
0.00128092
0.00096038
0.00072046
0.00054025
Ramin Shamshiri
EGM6341, HW #3
Due 05/2/09
#2
Bisection method
Solutions:
f(x) = exp(x)-3x2 = 0
a)
4
50
exp(x)
3*x^2
40
30
0
-1
4 x
20
-2
10
-4
0
-6
-10
-1
-8
Finding r1
x0
x1
f0
f1
x2
f2
|xn-xn-1|
-1
-2.6321206
-0.5
-0.14347
-0.5
-0.1434693
-0.25
0.591301
2.500E-01
-0.5
-0.25
-0.1434693
0.59130078
-0.375
0.265414
1.250E-01
-0.5
-0.375
-0.1434693
0.26541428
-0.4375
0.07143
6.250E-02
-0.5
-0.4375
-0.1434693
0.07142978
-0.46875
-0.0334
3.125E-02
-0.4375
-0.46875
0.0714298
-0.0333957
-0.453125
0.019672
1.563E-02
-0.46875
-0.453125
-0.0333957
0.01967188
-0.4609375
-0.0067
7.813E-03
-0.453125
-0.4609375
0.0196719
-0.006698
-0.45703125
0.006528
3.906E-03
-0.4609375
-0.4570313
-0.006698
0.00652786
-0.45898438
-7.5E-05
1.953E-03
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|
-0.2817182
0.5
0.898721
0.5
-0.2817182
0.89872127
0.75
0.4295
2.500E-01
0.75
-0.2817182
0.42950002
0.875
0.102
1.250E-01
0.875
-0.2817182
0.10200029
0.9375
-0.08313
6.250E-02
0.875
0.9375
0.1020003
-0.0831293
0.90625
0.011157
3.125E-02
0.9375
0.90625
-0.0831293
0.01115658
0.921875
-0.03556
1.563E-02
0.90625
0.921875
0.0111566
-0.0355608
0.9140625
-0.0121
7.813E-03
0.90625
0.9140625
0.0111566
-0.0120951
0.91015625
-0.00044
3.906E-03
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
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|
-0.2817182
6.59815003
2.5
-6.56751
2.5
6.59815
-6.567506
3.25
-5.89716
7.500E-01
3.25
6.59815
-5.8971601
3.625
-1.89715
3.750E-01
3.625
6.59815
-1.8971518
3.8125
1.657987
1.875E-01
3.625
3.8125
-1.8971518
1.65798743
3.71875
-0.27446
9.375E-02
3.8125
3.71875
1.6579874
-0.2744588
3.765625
0.650897
4.688E-02
3.71875
3.765625
-0.2744588
0.65089669
3.7421875
0.178278
2.344E-02
3.71875
3.7421875
-0.2744588
0.17827846
3.73046875
-0.05054
1.172E-02
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.
Ramin Shamshiri
EGM6341, HW #3
Due 05/2/09
f(x) = x3 - x2 x -1 = 0
b)
10
5
0
-2
-1
-5
-10
x0
x1
f0
f1
x2
f2
|xn-xn-1|
-1
-2
0.5
-1.625
0.5
-1.625
1.25
-1.85938
7.500E-01
1.25
-1.85938
1.625
-0.97461
3.750E-01
1.625
-0.97461
1.8125
-0.14331
1.875E-01
1.8125
-0.14331
1.90625
0.386871
9.375E-02
1.8125
1.90625
-0.14331
0.386871
1.859375
0.111721
4.688E-02
1.8125
1.859375
-0.14331
0.111721
1.8359375
-0.01827
2.344E-02
1.859375
1.835938
0.111721
-0.01827
1.8476563
0.046101
1.172E-02
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
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
Ramin Shamshiri
EGM6341, HW #3
Due 05/2/09
f(x)=exp(x)-1/(0.1+x2)
c)
6
2
-3
-2
-1
-2 0
x2
f2
-6
-10
x0
x1
f0
f1
|xn-xn-1|
-9
1.809191
0.5
-1.20842
0.5
1.809191
-1.20842
0.75
0.607566
2.500E-01
0.5
0.75
-1.20842
0.607566
0.625
-0.16997
1.250E-01
0.75
0.625
0.607566
-0.16997
0.6875
0.242489
6.250E-02
0.625
0.6875
-0.16997
0.242489
0.65625
0.043119
3.125E-02
0.625
0.65625
-0.16997
0.043119
0.640625
-0.06158
1.563E-02
0.65625
0.640625
0.043119
-0.06158
0.648438
-0.00879
7.813E-03
0.65625
0.648438
0.043119
-0.00879
0.652344
0.017276
3.906E-03
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
Ramin Shamshiri
EGM6341, HW #3
Due 05/2/09
d)
f(x)=x-1-0.3cos(x)
2
1
0
-2
-1.5
-1
-0.5
0.5
1.5
-1
-2
-3
x0
x1
f0
f1
x2
f2
|xn-xn-1|
-1.3
1.124844
-0.16209
1.124844
-0.16209
1.5
0.478779
5.000E-01
1.5
-0.16209
0.478779
1.25
0.155403
2.500E-01
1.25
-0.16209
0.155403
1.125
-0.00435
1.250E-01
1.25
1.125
0.155403
-0.00435
1.1875
0.075306
6.250E-02
1.125
1.1875
-0.00435
0.075306
1.15625
0.035418
3.125E-02
1.125
1.15625
-0.00435
0.035418
1.140625
0.015517
1.563E-02
1.125
1.140625
-0.00435
0.015517
1.1328125
0.005578
7.813E-03
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
Ramin Shamshiri
EGM6341, HW #3
Due 05/2/09
#4
Newtons method
Solutions:
f(x) = exp(x)-3x2 = 0
a)
Finding r1
n
r1
|xn-xn-1|
-1
-0.58665666
0.4133433
-0.469801908
0.1168548
-0.459053917
0.010748
-0.458962274
9.164E-05
-0.458962268
6.658E-09
Finding r2
n
xn
|xn-xn-1|
0.91415528
0.085844718
0.91001767
0.004137616
0.91000757
1.00932E-05
0.91000757
6.0179E-11
Finding r3
n
xn
0
Ramin Shamshiri
|xn-xn-1|
3
EGM6341, HW #3
Due 05/2/09
6.315435464
3.315435
5.474149483
8.413E-01
4.751646064
7.225E-01
4.201134676
5.505E-01
3.868723026
3.324E-01
3.747916888
1.208E-01
3.733278953
1.464E-02
3.733079065
1.999E-04
3.733079029
3.686E-08
f(x) = x3 - x2 x -1 = 0
b)
n
xn
|xn-xn-1|
2.3
0.7
1.95170399
3.483E-01
1.84847377
1.032E-01
1.83935569
9.118E-03
1.83928676
6.894E-05
1.83928676
3.925E-09
f(x)=exp(x)-1/(0.1+x2)
c)
xn
|xn-xn-1|
0.58610873
0.41389127
0.645119782
0.059011052
0.649727346
0.004607564
0.649750681
2.33349E-05
Ramin Shamshiri
EGM6341, HW #3
Due 05/2/09
d)
0.649750682
5.89759E-10
f(x)=x-1-0.3cos(x)
n
#9
xn
|xn-xn-1|
-2
1.953676238
3.953676
1.119933931
0.833742
1.128428782
0.008495
1.128425093
3.69E-06
Secant method
Solutions:
f(x) = exp(x)-3x2 = 0
a)
Finding r1
n
x0
x1
x2
f0
f1
f2
error
-1
-0.2753213
-2.63212
0.5319228
-1
-0.27532126
-0.3971505
-2.63212
0.531923
0.1990472
1.22E-01
-0.2753213
-0.39715054
-0.4699999
0.53192
0.199047
-0.037697
7.28E-02
-0.3971505
-0.46999990
-0.4583999
0.19905
-0.0377
0.0019031
1.16E-02
-0.4699999
-0.45839993
-0.4589574
-0.0377
0.001903
1.653E-05
5.57E-04
-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
0.78020272
-0.28172
0.3557657
0.78020272
0.90286674
-0.28172
0.355766
0.0211592
1.23E-01
0.78020272
0.90286674
0.91062354
0.35577
0.021159
-0.001834
7.76E-03
0.90286674
0.91062354
0.91000496
0.02116
-0.00183
7.774E-06
6.19E-04
0.91062354
0.91000496
0.91000757
-0.00183
7.77E-06
2.827E-09
2.61E-06
Finding r3
Ramin Shamshiri
EGM6341, HW #3
Due 05/2/09
x0
x1
x2
f0
f1
f2
error
2.82271483
-4.61094
6.59815
-7.080698
2.82271483
3.43212293
6.59815
-7.0807
-4.396142
6.09E-01
2.82271483
3.43212293
4.43006988
-7.0807
-4.39614
25.060725
9.98E-01
3.43212293
4.43006988
3.58105651
-4.39614
25.06072
-2.560436
8.49E-01
4.43006988
3.58105651
3.65975864
25.0607
-2.56044
-1.329536
7.87E-02
3.58105651
3.65975864
3.74476739
-2.56044
-1.32954
0.2293184
8.50E-02
3.65975864
3.74476739
3.73226200
-1.32954
0.229318
-0.015846
1.25E-02
3.74476739
3.73226200
3.73307027
0.22932
-0.01585
-0.00017
8.08E-04
3.73226200
3.73307027
3.73307904
-0.01585
-0.00017
1.282E-07
8.76E-06
f(x) = x3 - x2 x -1 = 0
b)
n
x0
x1
x2
f0
f1
f2
error
2.517241379
14
43
6.096765
2.517241
2.272275572
43
6.096765
3.296784
2.45E-01
2.517241
2.272276
1.983845303
6.096765
3.296784
0.888218
2.88E-01
2.272276
1.983845
1.87747957
3.296784
0.888218
0.215574
1.06E-01
1.983845
1.87748
1.843390652
0.888218
0.215574
0.022526
3.41E-02
1.87748
1.843391
1.839412969
0.215574
0.022526
0.000691
3.98E-03
1.843391
1.839413
1.839287182
0.022526
0.000691
2.33E-06
1.26E-04
1.839413
1.839287
1.839286755
0.000691
2.33E-06
2.43E-10
4.27E-07
f(x)=exp(x)-1/(0.1+x2)
c)
n
x0
x1
x2
f0
f1
f2
error
0.80082071
1.809191
19.97565
0.8784118
0.800821
0.69966549
19.97565
0.878412
0.3168178
1.01E-01
0.800821
0.699665
0.64259974
0.878412
0.316818
-4.815E-02
5.71E-02
0.699665
0.6426
0.6501283
0.316818
-0.04815
2.522E-03
7.53E-03
Ramin Shamshiri
EGM6341, HW #3
Due 05/2/09
0.6426
0.650128
0.64975362
-0.04815
0.002522
1.961E-05
3.75E-04
0.650128
0.649754
0.64975068
0.002522
1.96E-05
-8.016E-09
2.94E-06
x2
f0
f1
f2
error
d)
f(x)= x-1-0.3cos(x)
x0
x1
1.1318299
-0.16209
2.296998
0.00432867
1.13183
1.12830271
2.296998
0.004329
-0.0001556
3.53E-03
1.13183
1.128303
1.12842507
0.004329
-0.00016
-2.669E-08
1.22E-04
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 x 0 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 ,
< <1. This can be easily modified to the form: = 2 , <b <1. With f an even integer. Then
a b 2 f /2 , < <1. And the number will be in standard floating-point form, once b is known.
This reduces the problem to that of calculating b for < b < 1. Use the linear interpolating formula x0=
1/3(2b+1), <b <1, as an initial guess for the Newton iteration for calculating square root of b.
Solution:
a)
b)
1
x0 (2b 1)
3
1
e0 b (2b 1)
3
maximum e0 occurs at
de0
1
0 , i.e. b (3 / 4) 2 0.5625 . This gives e0, max .
db
24
1 e n2
Since en 1
2 xn
, it is seen that
1 e 20
| e1 |
2 x0
Ramin Shamshiri
1 e 21 1 e 40
| e2 |
2 x1 23 x1x 20
EGM6341, HW #3
Due 05/2/09
e0
1 e 22
1
| e3 |
,
2 x2 2 7 x2 x 21x 40
e160
1 e 23
1
| e4 |
x0
1
1
, xn b
4
2
| e4 |
2416 215 ( 1 ) 7 ( 1 )8
2 4
| e0 |
1
24
, it follows that
2.12 10 20
<
2 48 = 3.6 10 15
Thus 4 iterations are definitely enough to reduce the error on the 4th iteration to less than machine
epsilon.
On the other hand, since
that
x3 will have only half of the significant digits comparing with x 4 , it is likely
| e3 | will be on the order of O(10 10 ) or a little smaller. (In reality, through trial-and-error, we
48
the specified tolerance). Thus 3 iterations are NOT enough to bring the error down to 2
level.
Hence 4 iterations are required number of Newtons iteration.
Improvement of x0:
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 x0
Ramin Shamshiri
EGM6341, HW #3
Due 05/2/09
1
sqrt(b)
fit1
0.9
fit2
0.8
0.7
0.6
0.5
0.25
0.5
0.75
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)
we need
to converge
Since the smaller value of |g(r)| gives faster convergence, the best we can achieve is to set
to 0. This results in
1 + c f(x) = 0
=>
c = -1/f(x)
=>
xn 1 xn
g(x)
f ( xn )
f ' ( xn )
#23
The iteration xn1 2 (1 c) xn cxn3 will converge to =1 for some values of c. Find the values of
c for which this is true. For what value of c will the convergence be quadratic?
Ramin Shamshiri
EGM6341, HW #3
Due 05/2/09
Solution:
First we observe from the given iteration that
g ( x ) 2 (1 c) x cx 3
Thus the first order derivative of g(x) is:
g '( x ) (1 c) 3cx 2
Since the iteration converges to =1, the derivative at the root is
g '( ) (1 c) 3c 1 2c
Convergence requires | g '( ) | 1 so that
1 1 2c 1
Thus
0 c 1
1 2c 0
so that
c= .
#24
Solution:
a)
r=2
g(2) = 6-12/4=3>1
b)
g ( x)
2
1
x
3
x2
r =31/3
g(31/3) = 2/3- 2/3 = 0 <1 => will CONVERGE.
Ramin Shamshiri
EGM6341, HW #3
Due 05/2/09
c)
g(3) = -12/16=-0.75.
#25
Solution:
xn 1
a.
xn ( xn2 3a)
(1)
3xn2 a
x n of this iterative scheme must exist.
x0 >0 (which is a reasonable thing to assume for finding square root), we can see that
from (1),
x1 > 0.
Assume it is true for
Second, since
xn 1 a
xn ( xn2 3a)
3xn2 a
( xn a ) 3
3xn2 a
if
x0 a , then x1 a
using induction.
If
x0 a
using induction.
Third, since
then x1
xn 1 xn
2 xn (a xn2 )
3xn2 a
a xn 1 xn
xn xn 1 a
Thus the limit of
Ramin Shamshiri
we get
if x0
if
(2)
a,
x0 a .
x n exists.
EGM6341, HW #3
Due 05/2/09
L
It can be easily found that L=
b.
(2) =>
en 1
en3
3xn2 a
#39
L( L2 3a)
3L2 a
a.
=>
en 1
en3
xn a
1
3xn2 a
en 1
so that
en3
1
.
4a
Solution:
zn
f(zn)
(2.462611,
4.645821)
(2.810165,
-0.9090271)
(2.470614,
4.640501)
(4.7531128E-03,
1.1505127E-02)
(2.470639,
4.640533)
(-7.6293945E-05,
4.5776367E-05)
(2.470639,
4.640533)
(1.2969971E-04,
4.5776367E-05)
Ramin Shamshiri
EGM6341, HW #3
Due 05/2/09