Course Test · University: upper level
Numerical analysis: independent answers
Test Independent answers RatMath answers
Each answer here was worked out by hand, without RatMath, before the RatMath code was written. Where the arithmetic is long, the working says how it was checked.
1. Floating point
What exact rational number does the double nearest to 0.1 equal? What is machine epsilon (the gap from 1 to the next double)?
Answer
0.1 = 0.000110011 … 2 0.1 = 0.000110011\ldots_2 0.1 = 0.000110011 … 2 ; rounded to 53 significant bits it is
3602879701896397 2 55 \dfrac{3602879701896397}{2^{55}} 2 55 3602879701896397 , slightly above 0.1. Machine epsilon is
2 − 52 ≈ 2.22 × 10 − 16 2^{-52} \approx 2.22\times10^{-16} 2 − 52 ≈ 2.22 × 1 0 − 16 .
2. Catastrophic cancellation
Evaluate
x + 1 − x \sqrt{x + 1} - \sqrt{x} x + 1 − x at
x = 10 16 x = 10^{16} x = 1 0 16 in double precision. What goes wrong, and what is the true value?
Answer
10 16 + 1 10^{16} + 1 1 0 16 + 1 rounds to
10 16 10^{16} 1 0 16 , so the computed difference is 0, with every digit lost. Rewriting as
1 x + 1 + x ≈ 5 × 10 − 9 \dfrac{1}{\sqrt{x+1} + \sqrt x} \approx 5\times10^{-9} x + 1 + x 1 ≈ 5 × 1 0 − 9 gives the true value.
3. Bisection
Bisection on
x 2 − 2 x^2 - 2 x 2 − 2 over
[ 1 , 2 ] [1, 2] [ 1 , 2 ] : how many steps until the guaranteed error
( b − a ) / 2 n + 1 (b - a)/2^{n+1} ( b − a ) / 2 n + 1 is below
10 − 6 10^{-6} 1 0 − 6 ?
Answer
2 − ( n + 1 ) < 10 − 6 2^{-(n+1)} < 10^{-6} 2 − ( n + 1 ) < 1 0 − 6 needs
n + 1 ≥ 20 n + 1 \ge 20 n + 1 ≥ 20 (
2 20 = 1048576 2^{20} = 1048576 2 20 = 1048576 ): 19 halvings, i.e. 20 midpoints counting the first, with bound
2 − 20 ≈ 9.54 × 10 − 7 2^{-20} \approx 9.54\times10^{-7} 2 − 20 ≈ 9.54 × 1 0 − 7 .
4. Newton's method
Apply Newton's method to
x 2 − 2 x^2 - 2 x 2 − 2 from
x 0 = 1 x_0 = 1 x 0 = 1 . Give
x 1 , x 2 , x 3 x_1, x_2, x_3 x 1 , x 2 , x 3 .
Answer
x k + 1 = 1 2 ( x k + 2 / x k ) x_{k+1} = \tfrac12(x_k + 2/x_k) x k + 1 = 2 1 ( x k + 2/ x k ) :
3 2 \tfrac32 2 3 ,
17 12 \tfrac{17}{12} 12 17 ,
577 408 ≈ 1.4142157 \tfrac{577}{408} \approx 1.4142157 408 577 ≈ 1.4142157 . The correct digits roughly double each step.
5. Secant method
Apply the secant method to
x 2 − 2 x^2 - 2 x 2 − 2 from
x 0 = 1 x_0 = 1 x 0 = 1 ,
x 1 = 2 x_1 = 2 x 1 = 2 . Give
x 2 x_2 x 2 and
x 3 x_3 x 3 .
Answer
x 2 = 2 − 2 ⋅ 2 − 1 2 − ( − 1 ) = 4 3 x_2 = 2 - 2\cdot\dfrac{2 - 1}{2 - (-1)} = \tfrac43 x 2 = 2 − 2 ⋅ 2 − ( − 1 ) 2 − 1 = 3 4 ;
x 3 = 4 3 − ( − 2 9 ) 4 / 3 − 2 − 2 / 9 − 2 = 7 5 x_3 = \tfrac43 - \left(-\tfrac29\right)\dfrac{4/3 - 2}{-2/9 - 2} = \tfrac75 x 3 = 3 4 − ( − 9 2 ) − 2/9 − 2 4/3 − 2 = 5 7 .
6. Fixed-point iteration
For
x k + 1 = cos x k x_{k+1} = \cos x_k x k + 1 = cos x k , by what factor does the error shrink each step near the fixed point?
Answer
∣ g ′ ( x ∗ ) ∣ = sin x ∗ ≈ sin 0.7390851 ≈ 0.6736 |g'(x^*)| = \sin x^* \approx \sin 0.7390851 \approx 0.6736 ∣ g ′ ( x ∗ ) ∣ = sin x ∗ ≈ sin 0.7390851 ≈ 0.6736 : linear convergence with that ratio.
7. Interpolation
Find the polynomial through
( 0 , 1 ) (0, 1) ( 0 , 1 ) ,
( 1 , 3 ) (1, 3) ( 1 , 3 ) ,
( 2 , 7 ) (2, 7) ( 2 , 7 ) and evaluate it at 3.
Answer
Divided differences: 1; 2, 4; 1.
p = 1 + 2 x + x ( x − 1 ) = x 2 + x + 1 p = 1 + 2x + x(x - 1) = x^2 + x + 1 p = 1 + 2 x + x ( x − 1 ) = x 2 + x + 1 ,
p ( 3 ) = 13 p(3) = 13 p ( 3 ) = 13 .
8. Natural cubic spline
Find the natural cubic spline through
( 0 , 0 ) (0, 0) ( 0 , 0 ) ,
( 1 , 1 ) (1, 1) ( 1 , 1 ) ,
( 2 , 0 ) (2, 0) ( 2 , 0 ) and its value at
x = 1 2 x = \tfrac12 x = 2 1 .
Answer
With
M 0 = M 2 = 0 M_0 = M_2 = 0 M 0 = M 2 = 0 :
4 M 1 = 6 ( 0 − 2 + 0 ) = − 12 4M_1 = 6(0 - 2 + 0) = -12 4 M 1 = 6 ( 0 − 2 + 0 ) = − 12 ,
M 1 = − 3 M_1 = -3 M 1 = − 3 . On
[ 0 , 1 ] [0, 1] [ 0 , 1 ] :
S = − 1 2 x 3 + 3 2 x S = -\tfrac12x^3 + \tfrac32x S = − 2 1 x 3 + 2 3 x , so
S ( 1 2 ) = 3 4 − 1 16 = 11 16 S(\tfrac12) = \tfrac34 - \tfrac1{16} = \tfrac{11}{16} S ( 2 1 ) = 4 3 − 16 1 = 16 11 .
9. Chebyshev nodes
Give the three Chebyshev nodes on
[ − 1 , 1 ] [-1, 1] [ − 1 , 1 ] .
Answer
cos ( 2 i + 1 ) π 6 \cos\dfrac{(2i + 1)\pi}{6} cos 6 ( 2 i + 1 ) π :
3 2 , 0 , − 3 2 ≈ ± 0.8660254 \tfrac{\sqrt3}2, 0, -\tfrac{\sqrt3}2 \approx \pm0.8660254 2 3 , 0 , − 2 3 ≈ ± 0.8660254 .
10. Least squares
Fit a least-squares line to
( 0 , 1 ) (0, 1) ( 0 , 1 ) ,
( 1 , 3 ) (1, 3) ( 1 , 3 ) ,
( 2 , 4 ) (2, 4) ( 2 , 4 ) ,
( 3 , 4 ) (3, 4) ( 3 , 4 ) .
Answer
x ˉ = 1.5 \bar x = 1.5 x ˉ = 1.5 ,
y ˉ = 3 \bar y = 3 y ˉ = 3 ,
S x y = 5 S_{xy} = 5 S x y = 5 ,
S x x = 5 S_{xx} = 5 S xx = 5 : slope 1, intercept
3 − 1.5 = 1.5 3 - 1.5 = 1.5 3 − 1.5 = 1.5 .
y = x + 3 2 y = x + \tfrac32 y = x + 2 3 .
11. Richardson extrapolation
Estimate
f ′ ( 0 ) f'(0) f ′ ( 0 ) for
f = e x f = e^x f = e x with central differences at
h = 0.1 h = 0.1 h = 0.1 and
h = 0.05 h = 0.05 h = 0.05 , then one Richardson step.
Answer
D ( 0.1 ) = e 0.1 − e − 0.1 0.2 ≈ 1.0016675 D(0.1) = \dfrac{e^{0.1} - e^{-0.1}}{0.2} \approx 1.0016675 D ( 0.1 ) = 0.2 e 0.1 − e − 0.1 ≈ 1.0016675 ,
D ( 0.05 ) ≈ 1.0004167 D(0.05) \approx 1.0004167 D ( 0.05 ) ≈ 1.0004167 .
4 D ( 0.05 ) − D ( 0.1 ) 3 ≈ 0.99999979 \dfrac{4D(0.05) - D(0.1)}{3} \approx 0.99999979 3 4 D ( 0.05 ) − D ( 0.1 ) ≈ 0.99999979 , error about
2 × 10 − 7 2\times10^{-7} 2 × 1 0 − 7 instead of
4 × 10 − 4 4\times10^{-4} 4 × 1 0 − 4 .
12. Trapezoid rule
Approximate
∫ 0 1 x 2 d x \int_0^1 x^2\,dx ∫ 0 1 x 2 d x by the trapezoid rule with 4 panels.
Answer
1 8 ( 0 + 2 ⋅ 1 + 4 + 9 16 + 1 ) = 11 32 = 0.34375 \tfrac18\left(0 + 2\cdot\tfrac{1 + 4 + 9}{16} + 1\right) = \tfrac{11}{32} = 0.34375 8 1 ( 0 + 2 ⋅ 16 1 + 4 + 9 + 1 ) = 32 11 = 0.34375 (exact
1 3 \tfrac13 3 1 ).
13. Simpson's rule
Apply Simpson's rule with one panel (three points) to
∫ 0 1 x 4 d x \int_0^1 x^4\,dx ∫ 0 1 x 4 d x .
Answer
1 6 ( 0 + 4 ⋅ 1 16 + 1 ) = 5 24 ≈ 0.2083 \tfrac16\left(0 + 4\cdot\tfrac1{16} + 1\right) = \tfrac{5}{24} \approx 0.2083 6 1 ( 0 + 4 ⋅ 16 1 + 1 ) = 24 5 ≈ 0.2083 (exact
1 5 \tfrac15 5 1 ).
14. Gaussian quadrature
Apply two-point Gauss–Legendre quadrature to
∫ − 1 1 x 4 d x \int_{-1}^1 x^4\,dx ∫ − 1 1 x 4 d x .
Answer
Nodes
± 1 / 3 \pm1/\sqrt3 ± 1/ 3 , weights 1:
2 ⋅ 1 9 = 2 9 2\cdot\tfrac19 = \tfrac29 2 ⋅ 9 1 = 9 2 (exact
2 5 \tfrac25 5 2 ; the rule is exact only up to degree 3).
15. Euler's method
Use Euler's method with
h = 0.1 h = 0.1 h = 0.1 on
y ′ = y y' = y y ′ = y ,
y ( 0 ) = 1 y(0) = 1 y ( 0 ) = 1 , up to
t = 0.5 t = 0.5 t = 0.5 .
Answer
Each step multiplies by 1.1:
1.1 5 = 1.61051 1.1^5 = 1.61051 1. 1 5 = 1.61051 (exact
e 0.5 ≈ 1.64872 e^{0.5} \approx 1.64872 e 0.5 ≈ 1.64872 ).
16. Runge–Kutta
Take one classical RK4 step of size 0.1 on
y ′ = y y' = y y ′ = y ,
y ( 0 ) = 1 y(0) = 1 y ( 0 ) = 1 .
Answer
1 + h + h 2 2 + h 3 6 + h 4 24 = 1.1051708 3 ‾ 1 + h + \tfrac{h^2}2 + \tfrac{h^3}6 + \tfrac{h^4}{24} = 1.1051708\overline3 1 + h + 2 h 2 + 6 h 3 + 24 h 4 = 1.1051708 3 (exact
e 0.1 = 1.1051709181 e^{0.1} = 1.1051709181 e 0.1 = 1.1051709181 ).
17. Stability
For
y ′ = − 10 y y' = -10y y ′ = − 10 y , what is the largest step for which Euler's method does not grow?
Answer
Each step multiplies by
1 − 10 h 1 - 10h 1 − 10 h ;
∣ 1 − 10 h ∣ ≤ 1 |1 - 10h| \le 1 ∣1 − 10 h ∣ ≤ 1 needs
h ≤ 0.2 h \le 0.2 h ≤ 0.2 . The stability interval for
h λ h\lambda hλ is
[ − 2 , 0 ] [-2, 0] [ − 2 , 0 ] .
18. LU factorisation
Factor
A = ( 2 1 4 3 ) A = \begin{pmatrix}2&1\\4&3\end{pmatrix} A = ( 2 4 1 3 ) as
L U LU LU (no pivoting).
Answer
ℓ 21 = 2 \ell_{21} = 2 ℓ 21 = 2 :
L = ( 1 0 2 1 ) L = \begin{pmatrix}1&0\\2&1\end{pmatrix} L = ( 1 2 0 1 ) ,
U = ( 2 1 0 1 ) U = \begin{pmatrix}2&1\\0&1\end{pmatrix} U = ( 2 0 1 1 ) .
19. Condition number
Find
κ ∞ \kappa_\infty κ ∞ of
( 1 1 1 1.0001 ) \begin{pmatrix}1&1\\1&1.0001\end{pmatrix} ( 1 1 1 1.0001 ) .
Answer
∥ A ∥ ∞ = 2.0001 \|A\|_\infty = 2.0001 ∥ A ∥ ∞ = 2.0001 ;
A − 1 = 10 4 ( 1.0001 − 1 − 1 1 ) A^{-1} = 10^4\begin{pmatrix}1.0001&-1\\-1&1\end{pmatrix} A − 1 = 1 0 4 ( 1.0001 − 1 − 1 1 ) ,
∥ A − 1 ∥ ∞ = 20001 \|A^{-1}\|_\infty = 20001 ∥ A − 1 ∥ ∞ = 20001 .
κ = 2.0001 ⋅ 20001 = 40004.0001 \kappa = 2.0001\cdot20001 = 40004.0001 κ = 2.0001 ⋅ 20001 = 40004.0001 .
20. Iterative methods and eigenvalues
(a) Two Jacobi steps for
4 x + y = 1 4x + y = 1 4 x + y = 1 ,
x + 3 y = 2 x + 3y = 2 x + 3 y = 2 from
( 0 , 0 ) (0, 0) ( 0 , 0 ) . (b) The dominant eigenvalue of
( 2 1 1 3 ) \begin{pmatrix}2&1\\1&3\end{pmatrix} ( 2 1 1 3 ) by the power method.
Answer
(a)
( 1 4 , 2 3 ) (\tfrac14, \tfrac23) ( 4 1 , 3 2 ) , then
( 1 − 2 / 3 4 , 2 − 1 / 4 3 ) = ( 1 12 , 7 12 ) \left(\tfrac{1 - 2/3}{4}, \tfrac{2 - 1/4}{3}\right) = (\tfrac1{12}, \tfrac7{12}) ( 4 1 − 2/3 , 3 2 − 1/4 ) = ( 12 1 , 12 7 ) ; the solution is
( 1 11 , 7 11 ) (\tfrac1{11}, \tfrac7{11}) ( 11 1 , 11 7 ) . (b)
λ = 5 + 5 2 ≈ 3.618034 \lambda = \tfrac{5 + \sqrt5}{2} \approx 3.618034 λ = 2 5 + 5 ≈ 3.618034 .