Çankaya University
Department of Computer Engineering
2012 - 2013 Fall Semester
CENG 375 - Numerical Computations
First Midterm Examination
1) The equation x3 − cos(7x) = 0 has a solution on [0, 0.5]. Find it as accurately as possible.
2) The equation x3 − 7x2 + 8x + 1 = 0 has 3 roots. Find all of them.
3) Find a polynomial passing through the points
x −3 0
5
8
using
y 10 4 154 −980
a) Lagrange polynomial interpolation.
b) Newton polynomial interpolation. Show the divided difference table.
4) Find the free boundary cubic spline for x, y given below:
2
5
x 0
y 4 −12 −6
5) Estimate the derivative of f (x) = x5 ln x at x = 2 using
a) 3-point formula and h = 10−2
b) 3-point formula and h = 10−4
c) 5-point formula and h = 10−2
d) 5-point formula and h = 10−4
e) Which one of the above is most accurate? Make an educated guess.
Answers
1) Use Newton’s method with x0 = 0.25.
xn+1 = xn −
= xn −
n
0
1
2
3
4
f (xn )
f 0 (xn )
x3n − cos(7xn )
3x2n + 7 sin(7xn )
x
0.25
0.2225992861
0.2228190786
0.222819072
0.222819072
2) Using bisection method, we can locate the roots as follows:
x
−1 0 1 2 5 6
f (x) − + + − − +
The roots are on [−1, 0], [1, 2] and [5, 6]. Using Newton’s method:
xn+1 = xn −
=
n
0
1
2
3
4
5
6
x3n − 7x2n + 8xn + 1
3x2n − 14xn + 8
2x3n − 7x2n − 1
3x2n − 14xn + 8
x
−0.5
−0.1904761905
−0.1176547218
−0.1135504679
−0.113537611
−0.1135376109
−0.1135376109
n
0
1
2
3
4
5
x
1.5
1.6
1.596428571
1.596424375
1.596424379
1.596424379
n
0
1
2
3
4
x
5.5
5.517241379
5.517113239
5.517113232
5.517113232
3)
L(x) = 10
(x + 3)(x − 5)(x − 8)
(x + 3)x(x − 8)
(x + 3)x(x − 5)
x(x − 5)(x − 8)
+4
+ 154
− 980
(−3)(−8)(−11)
(3)(−5)(−8)
(8)(5)(−3)
(11)(8)(3)
y 1st DD 2nd DD 3rd DD
10
−2
0
4
4
30
−5
154
−51
5
−378
8 −980
x
−3
P (x) = 10 − 2(x + 3) + 4(x + 3)x − 5(x + 3)x(x − 5)
4)
S(x) =
a0 + b0 x + c0 x2 + d0 x3
06x<2
a + b (x − 2) + c (x − 2)2 + d (x − 2)3 2 6 x 6 5
1
1
1
1
S 0 (x) =
b0 + 2c0 x + 3d0 x2
06x<2
b + 2c (x − 2) + 3d (x − 2)2 2 6 x 6 5
1
1
1
S 00 (x) =
2c0 + 6d0 x
06x<2
2c + 6d (x − 2) 2 6 x 6 5
1
1
Conditions on S give:
a0
a1
2b0 + 4c0 + 8d0
3b1 + 9c1 + 27d1
=
=
=
=
4
−12
−16
6
Conditions on S 0 give:
b0 + 4c0 + 12d0 = b1
Conditions on S 00 give:
2c0 + 12d0 = 2c1
Natural Spline conditions give:
2c0 = 0
2c1 + 18d1 = 0
The solution of this set gives:
d1 = −
c1 = 3,
c1
,
9
d0 =
c1
,
6
1
d1 = − ,
3
b1 = 2 − 2c1 ,
1
d0 = ,
2
2
b0 = −8 − c1 ,
3
b1 = −4,
b0 − b1 = −2c1
b0 = −10
1 3
06x<2
4 − 10x + x
2
S(x) =
1
−12 − 4(x − 2) + 3(x − 2)2 − (x − 2)3 2 6 x 6 5
3
f (x0 + h) − f (x0 − h)
and
2h
f (x0 − 2h) − 8f (x0 − h) + 8f (x0 + h) − f (x0 + 2h)
f 0 (x0 ) ≈
with f (x) = x5 ln x, x0 = 2
12h
and given h values, we obtain:
5) Using the formulas f 0 (x0 ) ≈
a) f 0 (2) ≈ 71.4576804
b) f 0 (2) ≈ 71.45177503
c) f 0 (2) ≈ 71.45177433
d) f 0 (2) ≈ 71.45177444
e) We expect part d) to be the best approximation. 5-point formula gives better results
than 3-point for these h, and smaller h values are better as long as roundoff errors are
not important.
Çankaya University
Department of Computer Engineering
2012 - 2013 Fall Semester
CENG 375 - Numerical Computations
Second Midterm Examination
Z
12
cos(x2 ) dx using Boole’s Rule. (Single subinterval)
1) Estimate
0
Z
10
ln x dx using composite Simpson’s Rule and 3 subintervals.
2) Estimate
1
Z
4
3) Estimate
0
i
1
2
3
4
dx
using 4-point Gaussian Quadrature with coefficients:
1 + x4
wi
xi
0.65214515 −0.33998104
0.65214515
0.33998104
0.34785485 −0.86113631
0.34785485
0.86113631
4 2 1
4) a) Find LU factorization of A = 12 9 2
−8 11 0
b) Solve the system
5) a) Let x =
3
1
0
−12
9
8
4x1 + 2x2 + x3 = 1
12x1 + 9x2 + 2x3 = 3
−8x1 + 11x2 = 0
. Find kxk2 and kxk∞ .
b) Find the eigenvalues and eigenvectors of the matrix A =
3 1
5 7
Answers
1)
h=
12 − 0
=3
4
i
2 · 3h
I≈
7f (0) + 32f (3) + 12f (6) + 32f (9) + 7f (12)
45
≈ 0.9680334101
2)
h=
10 − 1
= 1.5
6
I≈
i
1.5 h
f (1) + 4f (2.5) + 2f (4) + 4f (5.5) + 2f (7)44f (8.5) + f (10)
3
≈ 14.00570703
3)
x = 2u + 2
Z
1
I=
f (u) du where f (u) =
−1
2
1 + (2 + 2u)4
I ≈ w1 f (x1 ) + w2 f (x2 ) + w3 f (x3 ) + w4 f (x4 )
≈ 1.0431438976262
4)
L
1 0 0
0 1 0
0 0 1
1 0 0
3 1 0
−2 0 1
1 0 0
3 1 0
−2 5 1
U
4 2 1
12 9 2
−8 11 0
4 2
1
0 3 −1
0 15
2
4 2
1
0 3 −1
0 0
7
LU x = b
Ly = b
y1 = 1
3y1 + y2 = 3
−2y1 + 5y2 + y3 = 0
y1 = 1
y2 = 0
y3 = 2
Ux = y
4x1 + 2x2 + x3 = 1
3x2 − x3 = 0
7x3 = 2
x3 = 2/7
x2 = 2/21
x1 = 11/84
5) a) kxk2 =
√
32 + 12 + 122 + 92 + 82 =
√
299 = 17.29
kxk∞ = 12
b) |A − λI| = 0
3−λ
1
5
7−λ
= (3 − λ)(7 − λ) = λ2 − 10λ + 16 = 0
Eigenvalues are λ = 2, λ = 8
λ=2
⇒
x1 + x2 = 0 An eigenvector is:
1
−1
λ=8
⇒
−5x1 + x2 = 0 An eigenvector is:
1
5
Çankaya University
Department of Computer Engineering
2012 - 2013 Fall Semester
CENG 375 - Numerical Computations
Final Examination
1) Find all the roots of the equation x4 − 2x3 − 12x2 + 9x + 22 = 0. The error must be less
than 10−2 .
Z 9
sin x dx
as accurately as possible.
2) Estimate the integral
x
1
3) Solve the system of equations
3x1 + 2x2 + x3 − 4x4
9x1 + 5x2 + x3 − 12x4
−6x1 − 11x2 − 14x3 + 13x4
12x1 + 8x2 + 8x3 − 5x4
=
=
=
=
6
20
10
42
using the LU-factorization of the coefficient
3
2
1 −4
1 0
9
5
1 −12 3 1
=
−6 −11 −14
13 −2 7
12
8
8 −5
4 0
matrix given as:
0 0
3
2
1 −4
0 0
0
0 −1 −2
1 0 0
0
2
5
2 1
0
0
0
1
−34 12 12
0 2 0
4) Find the eigenvalues and eigenvectors of the matrix A =
−90 30 32
5) Use
a) Jacobi Method
b) Gauss-Seidel Method to solve the system of equations:
5x + 2y + 2z = −74
2x + 7y + 4z = −229
−x + y + 3z = −223
Start with zero initial vector. Show the first three steps.
c) Will these iterations converge to the solution? Explain.
Answers
1) To find the roots, we have to check the sign of the function at certain points:
x −5 −4 −3 −2 −1 0 1 2 3 4 5
f + + + − + + + − − − +
Clearly, roots are on [−3, −2], [−2, −1], [1, 2], [4, 5].
Using Newton’s method:
xn+1 = xn −
= xn −
Starting
Starting
Starting
Starting
with
with
with
with
x0
x0
x0
x0
f (xn )
f 0 (xn )
x4n − 2x3n − 12x2n + 9xn + 22
4x3n − 6x2n − 24xn + 9
= −2.5, we obtain x = −2.640473275
= −1.5, we obtain x = −1.175360925
= 1.5, we obtain x = 1.738630168
= −2.5, we obtain x = 4.077204032
2) The exact result is I = 0.71895701.
Using Boole gives I ≈ 0.74827223 (One digit).
Composite Boole twice gives I ≈ 0.71902863 (three digits)
Composite Boole three times gives I ≈ 0.71896226 (5 digits).
3) Writing the system in matrix form
LU x = b
⇒
Ly = b,
y = Ux
We can first find y values as:
y1 = 6
3y1 + y2 = 20
⇒
y2 = 2
−2y1 + 7y2 + y3 = 10
⇒
y3 = 8
4y1 + 2y3 + y4 = 42
⇒
y4 = 2
Now using these, we can find x values as:
x4 = 2
2x3 + 5x4 = 8
⇒
x3 = −1
−x2 − 2x3 = 2
⇒
x2 = 0
3x1 + 2x2 + x3 − 4x4 = 6
⇒
x1 = 5
4)
−34 − λ 12
12
=0
0
2−λ
0
−90
30 32 − λ h
i
(2 − λ) (−34 − λ)(32 − λ) + 12 · 90 = 0
(2 − λ)(λ + 4)(λ − 2) = 0
Therefore the eigenvalues are λ = 2 (double root) and λ = −4. The eigenvectors are:
2
λ = −4 ⇒ v1 = 0
5
1
1
λ = 2 ⇒ v2 = 0 , v3 = 3
3
0
5) a) Jacobi Method:
xn+1 =
−74 − 2yn − 2zn
5
yn+1 =
−229 − 2xn − 4zn
7
zn+1 =
−223 + xn − yn
3
Starting with(x0 , y0 , z0 ) = (0, 0, 0) we obtain:
n
x
y
z
1 −14.8 −32.71 −74.33
2 28.02 13.99 −68.36
3 6.95 −1.66 −69.66
..
..
..
..
.
.
.
.
b) Gauss-Seidel Method:
xn+1 =
−74 − 2yn − 2zn
5
yn+1 =
−229 − 2xn+1 − 4zn
7
zn+1 =
−223 + xn+1 − yn+1
3
Starting with(x0 , y0 , z0 ) = (0, 0, 0) we obtain:
n
x
y
z
1 −14.8 −28.49 −69.77
2 24.50
0.15 −66.22
1.80 −71.06
3 11.62
..
..
..
..
.
.
.
.
c) Yes these methods will converge, because the coefficient matrix is strictly diagonally
dominant. In other words
5 > 2 + 2,
7 > 2 + 4,
3>1+1
Çankaya University
Department of Computer Engineering
CENG 375 - Numerical Computations
Due Date: 12.10.2012
HOMEWORK 1
1) Find a solution of x sin x = 1 in [0, 2] using bisection method.
2) Write a MATLAB program to find solutions using fixed point iteration. Find a solution
of ex + 3x − x2 − 2 = 0 using that program.
3) Find all roots of the polynomial equation 63x5 − 70x3 + 15x = 0
4) Find all intersection points of f (x) = ex and g(x) = 3x2
• Find the solution accurate to machine precision (16 digits)
• Give the starting point (or interval)
• Give the number of iterations necessary.
• Don’t forget to add the program .m file for second question.
Çankaya University
Department of Computer Engineering
CENG 375 - Numerical Computations
Due Date: 02.11.2012
HOMEWORK 2
1) Using Newton’s method, find all roots of x6 − x5 − 9x4 + 5x3 + 25x2 − 3x − 18 = 0. Find
the order of convergence α for all roots using a table.
2) Let f (x) = (x − 7)4/3 + 7. Clearly, x = 7 is a fixed point. Find the order of convergence
of the fixed point method
a) using a table,
b) without using a table.
Çankaya University
Department of Computer Engineering
CENG 375 - Numerical Computations
Due Date: 09.11.2012
HOMEWORK 2 - SOLUTION
1) Using Newton’s method, find all roots of x6 − x5 − 9x4 + 5x3 + 25x2 − 3x − 18 = 0. Find
the order of convergence α for all roots using a table.
A graph of the function shows that there are 4 roots:
Starting with appropriate initial points, we can find these roots using Newton’s method
as follows:
Newton(’x.^6-x.^5-9*x.^4+5*x.^3+25*x.^2-3*x-18’,
’6*x.^5-5*x.^4-36*x.^3+15*x.^2+50*x-3’,-2.5,10^-15) gives
x1 = −2.000000000000000
Similarly, we can find that the other roots are:
x2 = −1.302775619968090,
x3 = 1.000000000000000,
x4 = 2.302775629473824
Now using these solutions, we can find the error at each step and make a table using
Newton2.
i
1
2
3
4
5
6
7
8
x
-2.5000000000000000
-2.2713068181818183
-2.1173133241442650
-2.0322274350766070
-2.0032942584074855
-2.0000391657106680
-2.0000000056234275
-1.9999999999999991
Error
0.5000000000000000
0.2713068181818183
0.1173133241442650
0.0322274350766070
0.0032942584074855
0.0000391657106680
0.0000000056234275
0.0000000000000009
Using the relationship
en+1 ≈ λeαn
we obtain
ln λ = ln en+1 − α ln en
Now we will calculate λ using the data in the above table, supposing α = 1 or α = 2.
i
1
2
3
4
5
6
7
8
x
-2.5000000000000000
-2.2713068181818183
-2.1173133241442650
-2.0322274350766070
-2.0032942584074855
-2.0000391657106680
-2.0000000056234275
-1.9999999999999991
Error
0.5000000000000000
0.2713068181818183
0.1173133241442650
0.0322274350766070
0.0032942584074855
0.0000391657106680
0.0000000056234275
0.0000000000000009
λ (α = 1)
λ (α = 2)
0.5426136363636367 1.0852272727272734
0.4324009434427355 1.5937710166685108
0.2747124873639723 2.3416989448372214
0.1022190689285340 3.1718028035911567
0.0118890827079565 3.6090316050923392
0.0001435803769554 3.6659714455985575
0.0000001579425394 28.0865254079139780
It is clear from the table that, for α = 2 the λ approaches a fixed value as n approaches
infinity. The last value 28 is not reliable because of roundoff errors.
Therefore for x0 = −2, α = 2
For the next root the table looks very different:
i
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
x
-1.5000000000000000
-1.3897058823529411
-1.3449200722779933
-1.3235999584103715
-1.3131336875914730
-1.3079420129622668
-1.3053557670785834
-1.3040649505346062
-1.3034201077333043
-1.3030978263274546
-1.3029367204529061
-1.3028561762020023
-1.3028159062438467
-1.3027957718080159
-1.3027857047211657
-1.3027806712083070
-1.3027781544807924
-1.3027768961498334
-1.3027762669220637
-1.3027759521636217
Error
0.1972243800319100
0.0869302623848511
0.0421444523099033
0.0208243384422815
0.0103580676233830
0.0051663929941768
0.0025801471104934
0.0012893305665163
0.0006444877652143
0.0003222063593646
0.0001611004848161
0.0000805562339123
0.0000402862757567
0.0000201518399259
0.0000100847530757
0.0000050512402170
0.0000025345127024
0.0000012761817434
0.0000006469539737
0.0000003321955317
λ (α = 1)
λ (α = 2)
0.4407683389385541
0.4848076050124470
0.4941181413191149
0.4974020016094289
0.4987796162397902
0.4994097648788141
0.4997120362914940
0.4998623176643521
0.4999417781926385
0.4999916362103328
0.5000371911003217
0.5001012808087949
0.5002160052614333
0.5004383278563765
0.5008789188051949
0.5017604773286309
0.5035215417128184
0.5069450155324384
0.5134762985314494
2.23485726697
5.57697160588
11.7243934666
23.8856088027
48.1537323731
96.6650747323
193.675792461
387.691357550
775.719579449
1551.77457451
3103.88383791
6208.10155242
12416.5362984
24833.3814528
49666.9492097
99334.1151428
198666.016248
397235.752789
793682.888403
So for x2 = −1.302775619968090, α = 1. Convergence is much slower. The reason is
that this is a double root. f 0 (x2 ) = 0 and f (x2 ) = 0 at the same point.
For the next root x3 = 1 again we have α = 2, convergence is fast and the last λ is
unreliable:
i
1
2
3
4
5
6
x
0.5000000000000000
1.1250000000000000
0.9906939877876937
0.9999725518829801
0.9999999997489035
1.0000000000000002
Error
0.5000000000000000
0.1250000000000000
0.0093060122123063
0.0000274481170199
0.0000000002510965
0.0000000000000002
λ (α = 1)
λ (α = 2)
0.2500000000000001
0.5000000000000001
0.0744480976984505
0.5955847815876041
0.0029495036535238
0.3169460329767657
0.0000091480401647
0.3332847990291256
0.0000008842999616 3521.7537592845342000
For x4 = 2.302775629473824 we have α = 1 and convergence is slow.
i
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
x
2.5000000000000000
2.4134615384615383
2.3622881060785139
2.3338105661646891
2.3186530708774913
2.3108103713944090
2.3068178389299638
2.3048030561066701
2.3037909403719530
2.3032836891894597
2.3030297637181718
2.3029027258173786
2.3028391880513150
2.3028074144580084
2.3027915264853345
2.3027835822149627
2.3027796099995048
2.3027776238112176
2.3027766307220272
2.3027761340594339
Error
0.1972243705261758
0.1106859089877141
0.0595124766046897
0.0310349366908649
0.0158774414036671
0.0080347419205848
0.0040422094561396
0.0020274266328459
0.0010153108981288
0.0005080597156355
0.0002541342443476
0.0001270963435545
0.0000635585774909
0.0000317849841842
0.0000158970115103
0.0000079527411385
0.0000039805256806
0.0000019943373935
0.0000010012482030
0.0000005045856097
λ (α = 1)
λ (α = 2)
0.5612182140189607
0.5376698547174190
0.5214862237546213
0.5115989622218438
0.5060476506453439
0.5030913868911693
0.5015639725859619
0.5007879849657356
0.5003981702273196
0.5002054611429558
0.5001149840342205
0.5000818726434847
0.5000896092866161
0.5001421872084887
0.5002664263893003
0.5005224753696513
0.5010236218696353
0.5020455447015786
0.5039565696304255
2.84558248314
4.85761791753
8.76263690416
16.4846143337
31.8721157760
62.6145048420
124.081638526
247.006711292
492.852160997
984.540686358
1967.91654473
3934.66765965
7868.16868830
15735.1718128
31469.2120632
62937.1013908
125868.707318
251735.511929
503328.313712
2) Let f (x) = (x − 7)4/3 + 7. Clearly, x = 7 is a fixed point. Find the order of convergence
of the fixed point method
a) using a table,
b) without using a table.
a) Fixed point iteration, starting with x = 6.5 gives the following values:
i
1
2
3
4
5
6
7
8
9
10
x
6.5000000000000000
7.3968502629920501
7.2916322598940297
7.1933959689783258
7.1118398451043054
7.0538842789679581
7.0203524221022464
7.0055567578057341
7.0009842270368425
7.0000979024863383
Error
0.8968502629920501
0.1052180030980203
0.0982362909157040
0.0815561238740203
0.0579555661363473
0.0335318568657117
0.0147956642965124
0.0045725307688915
0.0008863245505042
0.0000933902521849
λ (α = 1)
λ (α = 2)
0.8968502629920501 0.8968502629920501
0.1173194762155664 0.1308127800778784
0.9336452700417417 8.8734365085028735
0.8302036153217878 8.4510887736404960
0.7106218807783364 8.7132865936104729
0.5785787129889135 9.9831431484551221
0.4412420211551661 13.1588901539885260
0.3090453174156812 20.8875594378367640
0.1938367602759849 42.3915704613125900
0.1053680078384209 118.8819691144532600
From this table, we can guess that 1 < α < 2 but it is not clear what exactly α is.
Let’s make another table:
i
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
x
6.5000000000000000
7.3968502629920501
7.2916322598940297
7.1933959689783258
7.1118398451043054
7.0538842789679581
7.0203524221022464
7.0055567578057341
7.0009842270368425
7.0000979024863383
7.0000045122341534
7.0000000745627933
7.0000000003138316
7.0000000000002132
7.0000000000000000
4
Now it is clear that α = .
3
Error
ln(en+1 )/ ln(en )
0.8968502629920501
0.1052180030980203 20.6833481441541420
0.0982362909157040 1.0304916611140547
0.0815561238740203 1.0801956244434086
0.0579555661363473 1.1362935286830056
0.0335318568657117 1.1921227404098176
0.0147956642965124 1.2409717995422385
0.0045725307688915 1.2786968898473738
0.0008863245505042 1.3045348541694595
0.0000933902521849 1.3201706588340505
0.0000044376713602 1.3283487405657828
0.0000000742489616 1.3318730128430532
0.0000000003136185 1.3330320730047072
0.0000000000002132 1.3333148182841683
0.0000000000000000
Inf
b) For this question, there is another, much easier way to find α.
The fixed point is 7, therefore at any step, the error is en = |xn − 7|.
Fixed point iteration gives:
xn+1 = (xn − 7)4/3 + 7
xn+1 − 7 = (xn − 7)4/3
en+1 = e4/3
n
4
⇒α= ,
3
λ=1
Çankaya University
Department of Computer Engineering
CENG 375 - Numerical Computations
Due Date: 09.11.2012
HOMEWORK 3
1) Find the Newton polynomial approximating f (x) = ex using the nodes
x0 = 0, x1 = 0.5, x2 = 1, x3 = 1.5, x4 = 2, x5 = 2.5. Then plot the resulting polynomial
and y = ex on the same graph. Find the maximum error on the interval [0, 2.5].
2) Find the Newton polynomial approximating f (x) = x cos(x2 ) using
a) 5 nodes
b) 10 nodes
√
on the interval [0, 10π]. Then plot the resulting polynomial and y = x cos(x2 ) on the
same graph.
Çankaya University
Department of Computer Engineering
CENG 375 - Numerical Computations
Due Date: 16.11.2012
HOMEWORK 4
1) Let x = [1 2 3 4 5 7 10 15 20]. Let y be your student number with each digit
considered separately. For example, if your ID# is 200911056 then y = [2 0 0 9 1 1 0 5 6].
Find the free boundary cubic spline for x, y and plot the graph.
2) Let x and y be as in question 1). Find the clamped cubic spline for x, y with
S 0 (1) = 1, S 0 (20) = −1 and plot the graph.
(Caution: You cannot use the program we wrote in lab directly. You have to modify it.)
Çankaya University
Department of Computer Engineering
CENG 375 - Numerical Computations
Due Date: 30.11.2012
HOMEWORK 5
Important Note: Among the parts of the following questions, only solve the one
corresponding to the last digit of your student ID number. For example, if your number
is 200911060, you have to solve I-0) and II-0).
I) Estimate the derivative of the function f (x) at x0 using 5-point rule with h1 = 10−4 and
h2 = 10−5 . Find exact value. Find errors. What is the ratio of errors?
0) f (x) = x sin x,
x0 = π/4
1) f (x) = x cos x,
x0 = π/3
2) f (x) = xex ,
x0 = 1
3) f (x) = xe−x ,
x0 = 3
7
4) f (x) = x − x, x0 = 1.375
√
5) f (x) = x, x0 = 5
6) f (x) = x3/2 ln x,
x0 = 1.2
7) f (x) = arctan x,
x0 = 2
8) f (x) =
1
,
1+x
x0 = 9
9) f (x) = sec x,
x0 = π/6
Z b
f (x) dx using composite Simpson’s rule and composite Boole’s
II) Estimate the integral
a
rule. In both cases, use a total number of 101 points. (NOT 101 subintervals.) Find
exact value. Find errors.
0) f (x) = sin 2x,
a = 0, b = π/8
−2x
1) f (x) = e , a = 0, b = 2
√
2) f (x) = x, a = 0, b = 4
3) f (x) = ln x,
4) f (x) =
1
,
x
a = 1, b = 10
a = 1, b = 8
5) f (x) = cos2 x,
−x2
6) f (x) = xe
7) f (x) =
,
1
,
1+x2
5
a = 0, b = π
a = 0, b = 1
a = 0, b = 2
8) f (x) = x ln x,
a = 1, b = 4
9) f (x) = tan x,
a = 0, b = π/4
Çankaya University
Department of Computer Engineering
CENG 375 - Numerical Computations
Due Date: 30.11.2012
HOMEWORK 5 - Solution
Important Note: Among the parts of the following questions, only solve the one
corresponding to the last digit of your student ID number. For example, if your number
is 200911060, you have to solve I-0) and II-0).
I) Estimate the derivative of the function f (x) at x0 using 5-point rule with h1 = 10−4 and
h2 = 10−5 . Find exact value. Find errors. What is the ratio of errors?
ANSWER:
0) f (x) = x sin x,
x0 = π/4
0
f (x) = sin x + x cos x
Exact Value: f 0 (x0 ) = 1.262467148456343
f 0 (x0 )
Error
h
−4
10
1.262467148456699 0.000000000000356
−5
10
1.262467148453276 0.000000000003067
Ratio of errors:
e1
= 0.116
e2
1) f (x) = x cos x,
x0 = π/3
f 0 (x) = cos x − x sin x
Exact Value: f 0 (x0 ) = −0.406899682117109
h
Deriv. Estimate
Error
10−4 −0.406899682116509 0.000000000000600
10−5 −0.406899682126039 0.000000000008930
Ratio of errors:
2) f (x) = xex ,
e1
= 0.067
e2
x0 = 1
f 0 (x) = ex + xex
Exact Value: f 0 (x0 ) = 5.436563656918091
Deriv. Estimate
Error
h
−4
10
5.436563656918691 0.000000000000600
−5
10
5.436563656961250 0.000000000043159
Ratio of errors:
e1
= 0.014
e2
3) f (x) = xe−x ,
x0 = 3
f 0 (x) = e−x − xe−x
Exact Value: f 0 (x0 ) = −0.099574136735728
Deriv. Estimate
Error
h
10−4 −0.099574136736211 0.000000000000483
10−5 −0.099574136736928 0.000000000001200
Ratio of errors:
e1
= 0.402
e2
4) f (x) = x7 − x,
x0 = 1.375
f 0 (x) = 7x6 − 1
Exact Value: f 0 (x0 ) = 46.305782318115234
h
Deriv. Estimate
Error
−4
10
46.305782318114545 0.000000000000689
−5
46.305782318634144 0.000000000518909
10
Ratio of errors:
√
5) f (x) = x,
1
f 0 (x) = √
2 x
e1
= 0.001
e2
x0 = 5
Exact Value: f 0 (x0 ) = 0.223606797749979
h
Deriv. Estimate
Error
−4
10
0.223606797747911 0.000000000002068
−5
10
0.223606797744580 0.000000000005399
Ratio of errors:
e1
= 0.383
e2
6) f (x) = x3/2 ln x, x0 = 1.2
3
f 0 (x) = x1/2 ln x + x1/2
2
Exact Value: f 0 (x0 ) = 1.395030003136857
h
Deriv. Estimate
Error
−4
10
1.395030003136534 0.000000000000323
−5
10
1.395030003153071 0.000000000016215
Ratio of errors:
e1
= 0.020
e2
7) f (x) = arctan x, x0 = 2
1
f 0 (x) =
1 + x2
Exact Value: f 0 (x0 ) = 0.200000000000000
Deriv. Estimate
Error
h
−4
10
0.200000000000385 0.000000000000385
−5
10
0.200000000005751 0.000000000005751
Ratio of errors:
e1
= 0.067
e2
1
,
1+x
−1
f 0 (x) =
(1 + x)2
8) f (x) =
x0 = 9
Exact Value: f 0 (x0 ) = −0.010000000000000
h
Deriv. Estimate
Error
−4
10
−0.009999999999964 0.000000000000036
−5
10
−0.009999999999594 0.000000000000406
Ratio of errors:
e1
= 0.089
e2
9) f (x) = sec x,
x0 = π/6
f 0 (x) = sec x tan x
Exact Value: f 0 (x0 ) = 0.666666666666667
h
Deriv. Estimate
Error
−4
10
0.666666666666038 0.000000000000629
−5
10
0.666666666663633 0.000000000003034
Ratio of errors:
e1
= 0.207
e2
Z
II) Estimate the integral
b
f (x) dx using composite Simpson’s rule and composite Boole’s
a
rule. In both cases, use a total number of 101 points. (NOT 101 subintervals.) Find
exact value. Find errors.
Answer: You have to use 50 subintervals for Simpson and 25 subintervals for Boole’s
rule.
0) f (x) = sin 2x, a = 0, b = π/8
Z
cos 2x
f (x) dx = −
2
Exact Value: I = 0.146446609406726
Method
Int. Estimate
Error
Simpson 0.146446609409822 0.000000000003096
Boole 0.146446609406726 0.000000000000000
1) f (x) = e−2x , a = 0, b = 2
Z
e−2x
f (x) dx = −
2
Exact Value: I = 0.490842180555633
Method
Int. Estimate
Error
Simpson 0.490842187535170 0.000000006979537
Boole 0.490842180559884 0.000000000004251
√
2) f (x) = x, a = 0, b = 4
Z
2
f (x) dx = x3/2
3
Exact Value: I = 5.333333333333333
Method
Int. Estimate
Error
Simpson 5.332683856533789 0.000649476799544
Boole 5.332763024453989 0.000570308879344
3) f (x) = ln x, a = 1, b = 10
Z
f (x) dx = x ln x − x
Exact Value: I = 14.025850929940461
Method
Int. Estimate
Error
Simpson 14.025850209899017 0.000000720041443
Boole 14.025850905864193 0.000000024076268
4) f (x) =
1
,
x
a = 1, b = 8
Z
f (x) dx = ln x
Exact Value: I = 2.079441541679836
Int. Estimate
Error
Method
Simpson 2.079442332675450 0.000000790995614
Boole 2.079441568735459 0.000000027055624
5) f (x) = cos2 x, a = 0, b = π
Z
1
1
f (x) dx = x + sin 2x
2
4
Exact Value: I = 1.570796326794897
Method
Int. Estimate
Error
Simpson 1.570796326794897 0.000000000000000
Boole 1.570796326794896 0.000000000000000
2
6) f (x) = xe−x , a = 0, b = 1
Z
2
e−x
f (x) dx = −
2
Exact Value: I = 0.316060279414279
Int. Estimate
Error
Method
Simpson 0.316060279952052 0.000000000537773
Boole 0.316060279414080 0.000000000000199
1
7) f (x) =
, a = 0, b = 2
1 + x2
Z
f (x) dx = arctan x
Exact Value: I = 1.107148717794090
Method
Int. Estimate
Error
Simpson 1.107148717589304 0.000000000204786
Boole 1.107148717794045 0.000000000000046
8) f (x) = x5 ln x, a = 1, b = 4
Z
x6
x6
f (x) dx =
ln x −
6
36
Exact Value: I = 832.626950524512040
Method
Int. Estimate
Error
Simpson 832.626959685723250 0.000009161211210
Boole 832.626950524768630 0.000000000256591
9) f (x) = tan x,
a = 0, b = π/4
Z
f (x) dx = − ln cos x
Exact Value: I = 0.346573590279973
Int. Estimate
Error
Method
Simpson 0.346573590575844 0.000000000295871
Boole 0.346573590280219 0.000000000000246
Çankaya University
Department of Computer Engineering
CENG 375 - Numerical Computations
Due Date: 07.12.2012
HOMEWORK 6
Important Note: Among the parts of the following questions, only solve the one
corresponding to the last digit of your student ID number modulo 5. For example, if your
number is 200911060 or 200911015, you have to solve I-0) and II-0).
Answers
Z
I) Evaluate integral
b
f (x) dx with an error less than 10−12 using any method you want:
a
1)
2)
3)
4)
√ −x
xe ,
b = 1 Answer: 0.378944691641
−3x2
f (x) = e
, a = −1, b = 1 Answer: 1.008687120463
2
f (x) = x2 e−x , a = 0, b = 2 Answer: 0.422725056492
sin x
, a = 1, b = 12 Answer: 0.558888171159
f (x) =
x
x
, a = 1, b = 4 Answer: 0.775087451080
f (x) = x
e −1
0) f (x) =
a = 0,
II) Extend our Composite Gaussian program to include Gaussian integrals of order 8. Then
estimate the following integral using 8 and 16 points:
−9
−15
0) f (x) = x cos x, a = π, b = 3π Answer: − 3.447236 × 10 , 4.359836 × 10
1) f (x) = x2 cos x, a = 0, b = 3π Answer: − 18.849490, −18.849556
2) f (x) = x sin x, a = π/2, b = 3π Answer: 8.424778, 8.424778
3) f (x) = x2 cos x, a = π, b = 2π Answer: 18.849556, 18.849556
4) f (x) = x cos x2 , a = 0, b = π Answer: − 0.214238, −0.215151
Çankaya University
Department of Computer Engineering
CENG 375 - Numerical Computations
Due Date: 14.12.2012
HOMEWORK 7
Modify the program GaussElim on
http://ceng375.cankaya.edu.tr/uploads/files/GaussElim.pdf
in such a way that if there is no unique solution, the program tests if there is no solution
or if there are infinitely many solutions, and then prints an appropriate error message.
Çankaya University
Department of Computer Engineering
CENG 375 - Numerical Computations
Due Date: 28.12.2012
HOMEWORK 8
Modify the program PowerMethod on
http://ceng375.cankaya.edu.tr/uploads/files/PowerMethod.pdf
in such a way that
• It gets the tolerance as input
• It gives the number of iterations as output
• It uses k · k2 norm to compare vectors. (The present version uses k · k∞ )
Then, test your program on the matrix
8 1 2 1
9 1 0 1
A=
0 2 10 12
1 1 2 4
Plot tolerance vs. operation count for tolerance = {10−1 , 10−2 , . . . , 10−14 }.
© Copyright 2026 Paperzz