CENG 375 - Numerical Computations First Midterm...
Transcript of CENG 375 - Numerical Computations First Midterm...
Cankaya UniversityDepartment 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 pointsx −3 0 5 8y 10 4 154 −980
using
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:
x 0 2 5y 4 −12 −6
5) Estimate the derivative of f(x) = x5 lnx 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 −f(xn)
f ′(xn)
= xn −x3n − cos(7xn)
3x2n + 7 sin(7xn)
n x0 0.251 0.22259928612 0.22281907863 0.2228190724 0.222819072
2) Using bisection method, we can locate the roots as follows:
x −1 0 1 2 5 6f(x) − + + − − +
The roots are on [−1, 0], [1, 2] and [5, 6]. Using Newton’s method:
xn+1 = xn −x3n − 7x2n + 8xn + 1
3x2n − 14xn + 8
=2x3n − 7x2n − 1
3x2n − 14xn + 8
n x0 −0.51 −0.19047619052 −0.11765472183 −0.11355046794 −0.1135376115 −0.11353761096 −0.1135376109
n x0 1.51 1.62 1.5964285713 1.5964243754 1.5964243795 1.596424379
n x0 5.51 5.5172413792 5.5171132393 5.5171132324 5.517113232
3)
L(x) = 10x(x− 5)(x− 8)
(−3)(−8)(−11)+ 4
(x+ 3)(x− 5)(x− 8)
(3)(−5)(−8)+ 154
(x+ 3)x(x− 8)
(8)(5)(−3)− 980
(x+ 3)x(x− 5)
(11)(8)(3)
x y 1stDD 2ndDD 3rdDD−3 10
−20 4 4
30 −55 154 −51
−3788 −980
P (x) = 10− 2(x+ 3) + 4(x+ 3)x− 5(x+ 3)x(x− 5)
4)
S(x) =
a0 + b0x+ c0x2 + d0x
3 0 6 x < 2
a1 + b1(x− 2) + c1(x− 2)2 + d1(x− 2)3 2 6 x 6 5
S ′(x) =
b0 + 2c0x+ 3d0x2 0 6 x < 2
b1 + 2c1(x− 2) + 3d1(x− 2)2 2 6 x 6 5
S ′′(x) =
2c0 + 6d0x 0 6 x < 2
2c1 + 6d1(x− 2) 2 6 x 6 5
Conditions on S give:
a0 = 4a1 = −12
2b0 + 4c0 + 8d0 = −163b1 + 9c1 + 27d1 = 6
Conditions on S ′ give:
b0 + 4c0 + 12d0 = b1
Conditions on S ′′ give:
2c0 + 12d0 = 2c1
Natural Spline conditions give:
2c0 = 02c1 + 18d1 = 0
The solution of this set gives:
d1 = − c19, d0 =
c16, b1 = 2− 2c1, b0 = −8− 2
3c1, b0 − b1 = −2c1
c1 = 3, d1 = − 1
3, d0 =
1
2, b1 = −4, b0 = −10
S(x) =
4− 10x+
1
2x3 0 6 x < 2
−12− 4(x− 2) + 3(x− 2)2 − 1
3(x− 2)3 2 6 x 6 5
5) Using the formulas f ′(x0) ≈f(x0 + h)− f(x0 − h)
2hand
f ′(x0) ≈f(x0 − 2h)− 8f(x0 − h) + 8f(x0 + h)− f(x0 + 2h)
12hwith f(x) = x5 lnx, x0 = 2
and given h values, we obtain:
a) f ′(2) ≈ 71.4576804
b) f ′(2) ≈ 71.45177503
c) f ′(2) ≈ 71.45177433
d) f ′(2) ≈ 71.45177444
e) We expect part d) to be the best approximation. 5-point formula gives better resultsthan 3-point for these h, and smaller h values are better as long as roundoff errors arenot important.
Cankaya UniversityDepartment of Computer Engineering
2012 - 2013 Fall Semester
CENG 375 - Numerical Computations
Second Midterm Examination
1) Estimate
∫ 12
0
cos(x2) dx using Boole’s Rule. (Single subinterval)
2) Estimate
∫ 10
1
lnx dx using composite Simpson’s Rule and 3 subintervals.
3) Estimate
∫ 4
0
dx
1 + x4using 4-point Gaussian Quadrature with coefficients:
i wi xi1 0.65214515 −0.339981042 0.65214515 0.339981043 0.34785485 −0.861136314 0.34785485 0.86113631
4)a) Find LU factorization of A =
4 2 112 9 2−8 11 0
b) Solve the system 4x1 + 2x2 + x3 = 1
12x1 + 9x2 + 2x3 = 3−8x1 + 11x2 = 0
5) a) Let x =
310
−1298
. Find ‖x‖2 and ‖x‖∞.
b) Find the eigenvalues and eigenvectors of the matrix A =
[3 15 7
]
Answers
1) h =12− 0
4= 3
I ≈ 2 · 345
[7f(0) + 32f(3) + 12f(6) + 32f(9) + 7f(12)
]
≈ 0.9680334101
2) h =10− 1
6= 1.5
I ≈ 1.5
3
[f(1) + 4f(2.5) + 2f(4) + 4f(5.5) + 2f(7)44f(8.5) + f(10)
]
≈ 14.00570703
3) x = 2u+ 2
I =
∫ 1
−1f(u) du where f(u) =
2
1 + (2 + 2u)4
I ≈ w1f(x1) + w2f(x2) + w3f(x3) + w4f(x4)
≈ 1.0431438976262
4)L U 1 0 0
0 1 00 0 1
4 2 112 9 2−8 11 0
1 0 0
3 1 0−2 0 1
4 2 10 3 −10 15 2
1 0 0
3 1 0−2 5 1
4 2 10 3 −10 0 7
LUx = b
Ly = b
y1 = 13y1 + y2 = 3
−2y1 + 5y2 + y3 = 0
y1 = 1y2 = 0y3 = 2
Ux = y
4x1 + 2x2 + x3 = 13x2 − x3 = 0
7x3 = 2
x3 = 2/7
x2 = 2/21
x1 = 11/84
5)a) ‖x‖2 =√
32 + 12 + 122 + 92 + 82 =√
299 = 17.29
‖x‖∞ = 12
b) |A− λI| = 0
∣∣∣∣ 3− λ 15 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:
[15
]
Cankaya UniversityDepartment 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 lessthan 10−2.
2) Estimate the integral
∫ 9
1
sinx dx
xas accurately as possible.
3) Solve the system of equations
3x1 + 2x2 + x3 − 4x4 = 69x1 + 5x2 + x3 − 12x4 = 20
−6x1 − 11x2 − 14x3 + 13x4 = 1012x1 + 8x2 + 8x3 − 5x4 = 42
using the LU-factorization of the coefficient matrix given as:3 2 1 −49 5 1 −12−6 −11 −14 1312 8 8 −5
=
1 0 0 03 1 0 0−2 7 1 0
4 0 2 1
3 2 1 −40 −1 −2 00 0 2 50 0 0 1
4) Find the eigenvalues and eigenvectors of the matrix A =
−34 12 120 2 0
−90 30 32
5) Use
a) Jacobi Method
b) Gauss-Seidel Method to solve the system of equations:
5x+ 2y + 2z = −742x+ 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 5f + + + − + + + − − − +
Clearly, roots are on [−3,−2], [−2,−1], [1, 2], [4, 5].Using Newton’s method:
xn+1 = xn −f(xn)
f ′(xn)
= xn −x4n − 2x3n − 12x2n + 9xn + 22
4x3n − 6x2n − 24xn + 9
Starting with x0 = −2.5, we obtain x = −2.640473275
Starting with x0 = −1.5, we obtain x = −1.175360925
Starting with x0 = 1.5, we obtain x = 1.738630168
Starting with x0 = −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
LUx = 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 2− λ 0−90 30 32− λ
∣∣∣∣∣∣ = 0
(2− λ)[(−34− λ)(32− λ) + 12 · 90
]= 0
(2− λ)(λ+ 4)(λ− 2) = 0
Therefore the eigenvalues are λ = 2 (double root) and λ = −4. The eigenvectors are:
λ = −4 ⇒ v1 =
205
λ = 2 ⇒ v2 =
103
, v3 =
130
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 z1 −14.8 −32.71 −74.332 28.02 13.99 −68.363 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 z1 −14.8 −28.49 −69.772 24.50 0.15 −66.223 11.62 1.80 −71.06...
......
...
c) Yes these methods will converge, because the coefficient matrix is strictly diagonallydominant. In other words
5 > 2 + 2, 7 > 2 + 4, 3 > 1 + 1
Cankaya University
Department of Computer Engineering
CENG 375 - Numerical Computations
Due Date: 12.10.2012
HOMEWORK 1
1) Find a solution of x sinx = 1 in [0, 2] using bisection method.
2) Write a MATLAB program to find solutions using fixed point iteration. Find a solutionof 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.
Cankaya 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. Findthe 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 convergenceof the fixed point method
a) using a table,
b) without using a table.
Cankaya 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. Findthe 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 methodas 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 usingNewton2.
i x Error1 -2.5000000000000000 0.50000000000000002 -2.2713068181818183 0.27130681818181833 -2.1173133241442650 0.11731332414426504 -2.0322274350766070 0.03222743507660705 -2.0032942584074855 0.00329425840748556 -2.0000391657106680 0.00003916571066807 -2.0000000056234275 0.00000000562342758 -1.9999999999999991 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 x Error λ (α = 1) λ (α = 2)1 -2.5000000000000000 0.50000000000000002 -2.2713068181818183 0.2713068181818183 0.5426136363636367 1.08522727272727343 -2.1173133241442650 0.1173133241442650 0.4324009434427355 1.59377101666851084 -2.0322274350766070 0.0322274350766070 0.2747124873639723 2.34169894483722145 -2.0032942584074855 0.0032942584074855 0.1022190689285340 3.17180280359115676 -2.0000391657106680 0.0000391657106680 0.0118890827079565 3.60903160509233927 -2.0000000056234275 0.0000000056234275 0.0001435803769554 3.66597144559855758 -1.9999999999999991 0.0000000000000009 0.0000001579425394 28.0865254079139780
It is clear from the table that, for α = 2 the λ approaches a fixed value as n approachesinfinity. 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 x Error λ (α = 1) λ (α = 2)1 -1.5000000000000000 0.19722438003191002 -1.3897058823529411 0.0869302623848511 0.4407683389385541 2.234857266973 -1.3449200722779933 0.0421444523099033 0.4848076050124470 5.576971605884 -1.3235999584103715 0.0208243384422815 0.4941181413191149 11.72439346665 -1.3131336875914730 0.0103580676233830 0.4974020016094289 23.88560880276 -1.3079420129622668 0.0051663929941768 0.4987796162397902 48.15373237317 -1.3053557670785834 0.0025801471104934 0.4994097648788141 96.66507473238 -1.3040649505346062 0.0012893305665163 0.4997120362914940 193.6757924619 -1.3034201077333043 0.0006444877652143 0.4998623176643521 387.69135755010 -1.3030978263274546 0.0003222063593646 0.4999417781926385 775.71957944911 -1.3029367204529061 0.0001611004848161 0.4999916362103328 1551.7745745112 -1.3028561762020023 0.0000805562339123 0.5000371911003217 3103.8838379113 -1.3028159062438467 0.0000402862757567 0.5001012808087949 6208.1015524214 -1.3027957718080159 0.0000201518399259 0.5002160052614333 12416.536298415 -1.3027857047211657 0.0000100847530757 0.5004383278563765 24833.381452816 -1.3027806712083070 0.0000050512402170 0.5008789188051949 49666.949209717 -1.3027781544807924 0.0000025345127024 0.5017604773286309 99334.115142818 -1.3027768961498334 0.0000012761817434 0.5035215417128184 198666.01624819 -1.3027762669220637 0.0000006469539737 0.5069450155324384 397235.75278920 -1.3027759521636217 0.0000003321955317 0.5134762985314494 793682.888403
So for x2 = −1.302775619968090, α = 1. Convergence is much slower. The reason isthat this is a double root. f ′(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 λ isunreliable:
i x Error λ (α = 1) λ (α = 2)1 0.5000000000000000 0.50000000000000002 1.1250000000000000 0.1250000000000000 0.2500000000000001 0.50000000000000013 0.9906939877876937 0.0093060122123063 0.0744480976984505 0.59558478158760414 0.9999725518829801 0.0000274481170199 0.0029495036535238 0.31694603297676575 0.9999999997489035 0.0000000002510965 0.0000091480401647 0.33328479902912566 1.0000000000000002 0.0000000000000002 0.0000008842999616 3521.7537592845342000
For x4 = 2.302775629473824 we have α = 1 and convergence is slow.
i x Error λ (α = 1) λ (α = 2)1 2.5000000000000000 0.19722437052617582 2.4134615384615383 0.1106859089877141 0.5612182140189607 2.845582483143 2.3622881060785139 0.0595124766046897 0.5376698547174190 4.857617917534 2.3338105661646891 0.0310349366908649 0.5214862237546213 8.762636904165 2.3186530708774913 0.0158774414036671 0.5115989622218438 16.48461433376 2.3108103713944090 0.0080347419205848 0.5060476506453439 31.87211577607 2.3068178389299638 0.0040422094561396 0.5030913868911693 62.61450484208 2.3048030561066701 0.0020274266328459 0.5015639725859619 124.0816385269 2.3037909403719530 0.0010153108981288 0.5007879849657356 247.00671129210 2.3032836891894597 0.0005080597156355 0.5003981702273196 492.85216099711 2.3030297637181718 0.0002541342443476 0.5002054611429558 984.54068635812 2.3029027258173786 0.0001270963435545 0.5001149840342205 1967.9165447313 2.3028391880513150 0.0000635585774909 0.5000818726434847 3934.6676596514 2.3028074144580084 0.0000317849841842 0.5000896092866161 7868.1686883015 2.3027915264853345 0.0000158970115103 0.5001421872084887 15735.171812816 2.3027835822149627 0.0000079527411385 0.5002664263893003 31469.212063217 2.3027796099995048 0.0000039805256806 0.5005224753696513 62937.101390818 2.3027776238112176 0.0000019943373935 0.5010236218696353 125868.70731819 2.3027766307220272 0.0000010012482030 0.5020455447015786 251735.51192920 2.3027761340594339 0.0000005045856097 0.5039565696304255 503328.313712
2) Let f(x) = (x − 7)4/3 + 7. Clearly, x = 7 is a fixed point. Find the order of convergenceof 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 x Error λ (α = 1) λ (α = 2)1 6.5000000000000000 0.8968502629920501 0.8968502629920501 0.89685026299205012 7.3968502629920501 0.1052180030980203 0.1173194762155664 0.13081278007787843 7.2916322598940297 0.0982362909157040 0.9336452700417417 8.87343650850287354 7.1933959689783258 0.0815561238740203 0.8302036153217878 8.45108877364049605 7.1118398451043054 0.0579555661363473 0.7106218807783364 8.71328659361047296 7.0538842789679581 0.0335318568657117 0.5785787129889135 9.98314314845512217 7.0203524221022464 0.0147956642965124 0.4412420211551661 13.15889015398852608 7.0055567578057341 0.0045725307688915 0.3090453174156812 20.88755943783676409 7.0009842270368425 0.0008863245505042 0.1938367602759849 42.391570461312590010 7.0000979024863383 0.0000933902521849 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 x Error ln(en+1)/ ln(en)1 6.5000000000000000 0.89685026299205012 7.3968502629920501 0.1052180030980203 20.68334814415414203 7.2916322598940297 0.0982362909157040 1.03049166111405474 7.1933959689783258 0.0815561238740203 1.08019562444340865 7.1118398451043054 0.0579555661363473 1.13629352868300566 7.0538842789679581 0.0335318568657117 1.19212274040981767 7.0203524221022464 0.0147956642965124 1.24097179954223858 7.0055567578057341 0.0045725307688915 1.27869688984737389 7.0009842270368425 0.0008863245505042 1.304534854169459510 7.0000979024863383 0.0000933902521849 1.320170658834050511 7.0000045122341534 0.0000044376713602 1.328348740565782812 7.0000000745627933 0.0000000742489616 1.331873012843053213 7.0000000003138316 0.0000000003136185 1.333032073004707214 7.0000000000002132 0.0000000000002132 1.333314818284168315 7.0000000000000000 0.0000000000000000 Inf
Now it is clear that α =4
3.
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/3n
⇒ α =4
3, λ = 1
Cankaya 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 nodesx0 = 0, x1 = 0.5, x2 = 1, x3 = 1.5, x4 = 2, x5 = 2.5. Then plot the resulting polynomialand 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 nodeson the interval [0,
√10π]. Then plot the resulting polynomial and y = x cos(x2) on the
same graph.
Cankaya 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 digitconsidered 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 withS ′(1) = 1, S ′(20) = −1 and plot the graph.(Caution: You cannot use the program we wrote in lab directly. You have to modify it.)
Cankaya 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 onecorresponding to the last digit of your student ID number. For example, if your numberis 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 andh2 = 10−5. Find exact value. Find errors. What is the ratio of errors?
0) f(x) = x sinx, x0 = π/4
1) f(x) = x cosx, x0 = π/3
2) f(x) = xex, x0 = 1
3) f(x) = xe−x, x0 = 3
4) f(x) = x7 − x, x0 = 1.375
5) f(x) =√x, x0 = 5
6) f(x) = x3/2 lnx, x0 = 1.2
7) f(x) = arctan x, x0 = 2
8) f(x) = 11+x
, x0 = 9
9) f(x) = sec x, x0 = π/6
II) Estimate the integral
∫ b
a
f(x) dx using composite Simpson’s rule and composite Boole’s
rule. In both cases, use a total number of 101 points. (NOT 101 subintervals.) Findexact value. Find errors.
0) f(x) = sin 2x, a = 0, b = π/8
1) f(x) = e−2x, a = 0, b = 2
2) f(x) =√x, a = 0, b = 4
3) f(x) = ln x, a = 1, b = 10
4) f(x) = 1x, a = 1, b = 8
5) f(x) = cos2 x, a = 0, b = π
6) f(x) = xe−x2, a = 0, b = 1
7) f(x) = 11+x2
, a = 0, b = 2
8) f(x) = x5 lnx, a = 1, b = 4
9) f(x) = tan x, a = 0, b = π/4
Cankaya 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 onecorresponding to the last digit of your student ID number. For example, if your numberis 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 andh2 = 10−5. Find exact value. Find errors. What is the ratio of errors?ANSWER:
0) f(x) = x sinx, x0 = π/4
f ′(x) = sin x+ x cosx
Exact Value: f ′(x0) = 1.262467148456343
h f ′(x0) Error10−4 1.262467148456699 0.000000000000356
10−5 1.262467148453276 0.000000000003067
Ratio of errors:e1e2
= 0.116
1) f(x) = x cosx, x0 = π/3
f ′(x) = cos x− x sinx
Exact Value: f ′(x0) = −0.406899682117109
h Deriv. Estimate Error10−4 −0.406899682116509 0.000000000000600
10−5 −0.406899682126039 0.000000000008930
Ratio of errors:e1e2
= 0.067
2) f(x) = xex, x0 = 1
f ′(x) = ex + xex
Exact Value: f ′(x0) = 5.436563656918091
h Deriv. Estimate Error10−4 5.436563656918691 0.000000000000600
10−5 5.436563656961250 0.000000000043159
Ratio of errors:e1e2
= 0.014
3) f(x) = xe−x, x0 = 3
f ′(x) = e−x − xe−x
Exact Value: f ′(x0) = −0.099574136735728
h Deriv. Estimate Error10−4 −0.099574136736211 0.000000000000483
10−5 −0.099574136736928 0.000000000001200
Ratio of errors:e1e2
= 0.402
4) f(x) = x7 − x, x0 = 1.375
f ′(x) = 7x6 − 1
Exact Value: f ′(x0) = 46.305782318115234
h Deriv. Estimate Error10−4 46.305782318114545 0.000000000000689
10−5 46.305782318634144 0.000000000518909
Ratio of errors:e1e2
= 0.001
5) f(x) =√x, x0 = 5
f ′(x) =1
2√x
Exact Value: f ′(x0) = 0.223606797749979
h Deriv. Estimate Error10−4 0.223606797747911 0.000000000002068
10−5 0.223606797744580 0.000000000005399
Ratio of errors:e1e2
= 0.383
6) f(x) = x3/2 lnx, x0 = 1.2
f ′(x) =3
2x1/2 lnx+ x1/2
Exact Value: f ′(x0) = 1.395030003136857
h Deriv. Estimate Error10−4 1.395030003136534 0.000000000000323
10−5 1.395030003153071 0.000000000016215
Ratio of errors:e1e2
= 0.020
7) f(x) = arctan x, x0 = 2
f ′(x) =1
1 + x2
Exact Value: f ′(x0) = 0.200000000000000
h Deriv. Estimate Error10−4 0.200000000000385 0.000000000000385
10−5 0.200000000005751 0.000000000005751
Ratio of errors:e1e2
= 0.067
8) f(x) =1
1 + x, x0 = 9
f ′(x) =−1
(1 + x)2
Exact Value: f ′(x0) = −0.010000000000000
h Deriv. Estimate Error10−4 −0.009999999999964 0.000000000000036
10−5 −0.009999999999594 0.000000000000406
Ratio of errors:e1e2
= 0.089
9) f(x) = sec x, x0 = π/6
f ′(x) = sec x tanx
Exact Value: f ′(x0) = 0.666666666666667
h Deriv. Estimate Error10−4 0.666666666666038 0.000000000000629
10−5 0.666666666663633 0.000000000003034
Ratio of errors:e1e2
= 0.207
II) Estimate the integral
∫ b
a
f(x) dx using composite Simpson’s rule and composite Boole’s
rule. In both cases, use a total number of 101 points. (NOT 101 subintervals.) Findexact value. Find errors.
Answer: You have to use 50 subintervals for Simpson and 25 subintervals for Boole’srule.
0) f(x) = sin 2x, a = 0, b = π/8∫f(x) dx = − cos 2x
2
Exact Value: I = 0.146446609406726
Method Int. Estimate ErrorSimpson 0.146446609409822 0.000000000003096
Boole 0.146446609406726 0.000000000000000
1) f(x) = e−2x, a = 0, b = 2∫f(x) dx = − e
−2x
2
Exact Value: I = 0.490842180555633
Method Int. Estimate ErrorSimpson 0.490842187535170 0.000000006979537
Boole 0.490842180559884 0.000000000004251
2) f(x) =√x, a = 0, b = 4∫
f(x) dx =2
3x3/2
Exact Value: I = 5.333333333333333
Method Int. Estimate ErrorSimpson 5.332683856533789 0.000649476799544
Boole 5.332763024453989 0.000570308879344
3) f(x) = ln x, a = 1, b = 10∫f(x) dx = x lnx− x
Exact Value: I = 14.025850929940461
Method Int. Estimate ErrorSimpson 14.025850209899017 0.000000720041443
Boole 14.025850905864193 0.000000024076268
4) f(x) =1
x, a = 1, b = 8
∫f(x) dx = lnx
Exact Value: I = 2.079441541679836
Method Int. Estimate ErrorSimpson 2.079442332675450 0.000000790995614
Boole 2.079441568735459 0.000000027055624
5) f(x) = cos2 x, a = 0, b = π∫f(x) dx =
1
2x+
1
4sin 2x
Exact Value: I = 1.570796326794897
Method Int. Estimate ErrorSimpson 1.570796326794897 0.000000000000000
Boole 1.570796326794896 0.000000000000000
6) f(x) = xe−x2, a = 0, b = 1∫
f(x) dx = − e−x2
2
Exact Value: I = 0.316060279414279
Method Int. Estimate ErrorSimpson 0.316060279952052 0.000000000537773
Boole 0.316060279414080 0.000000000000199
7) f(x) =1
1 + x2, a = 0, b = 2∫
f(x) dx = arctanx
Exact Value: I = 1.107148717794090
Method Int. Estimate ErrorSimpson 1.107148717589304 0.000000000204786
Boole 1.107148717794045 0.000000000000046
8) f(x) = x5 lnx, a = 1, b = 4∫f(x) dx =
x6
6lnx− x6
36
Exact Value: I = 832.626950524512040
Method Int. Estimate ErrorSimpson 832.626959685723250 0.000009161211210
Boole 832.626950524768630 0.000000000256591
9) f(x) = tan x, a = 0, b = π/4
∫f(x) dx = − ln cosx
Exact Value: I = 0.346573590279973
Method Int. Estimate ErrorSimpson 0.346573590575844 0.000000000295871
Boole 0.346573590280219 0.000000000000246
Cankaya 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 onecorresponding to the last digit of your student ID number modulo 5. For example, if yournumber is 200911060 or 200911015, you have to solve I-0) and II-0).
Answers
I) Evaluate integral
∫ b
a
f(x) dx with an error less than 10−12 using any method you want:
0) f(x) =√xe−x, a = 0, b = 1
(Answer: 0.378944691641
)1) f(x) = e−3x
2, a = −1, b = 1
(Answer: 1.008687120463
)2) f(x) = x2e−x
2, a = 0, b = 2
(Answer: 0.422725056492
)3) f(x) =
sinx
x, a = 1, b = 12
(Answer: 0.558888171159
)4) f(x) =
x
ex − 1, a = 1, b = 4
(Answer: 0.775087451080
)II) Extend our Composite Gaussian program to include Gaussian integrals of order 8. Then
estimate the following integral using 8 and 16 points:
0) f(x) = x cosx, a = π, b = 3π(Answer: − 3.447236× 10−9, 4.359836× 10−15
)1) f(x) = x2 cosx, a = 0, b = 3π
(Answer: − 18.849490, −18.849556
)2) f(x) = x sinx, a = π/2, b = 3π
(Answer: 8.424778, 8.424778
)3) f(x) = x2 cosx, a = π, b = 2π
(Answer: 18.849556, 18.849556
)4) f(x) = x cosx2, a = 0, b = π
(Answer: − 0.214238, −0.215151
)
Cankaya 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 solutionor if there are infinitely many solutions, and then prints an appropriate error message.
Cankaya 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 ‖ · ‖2 norm to compare vectors. (The present version uses ‖ · ‖∞)
Then, test your program on the matrix
A =
8 1 2 19 1 0 10 2 10 121 1 2 4
Plot tolerance vs. operation count for tolerance = {10−1, 10−2, . . . , 10−14}.