2020-04-01 21:11:45 +00:00
% vim: set ts=2 sw=2 et tw=80:
\documentclass [12pt,a4paper] { article}
\usepackage [utf8] { inputenc} \usepackage [margin=2cm] { geometry}
\usepackage { amstext}
\usepackage { amsmath}
\usepackage { array}
\usepackage [utf8] { inputenc}
\usepackage [margin=2cm] { geometry}
\usepackage { amstext}
\usepackage { array}
\newcommand { \lra } { \Leftrightarrow }
\newcolumntype { L} { >{ $ } l< { $ } }
\title { Midterm -- Introduction to Computational Science}
\author { Claudio Maggioni}
\begin { document}
\maketitle
\section * { Question 1}
\subsection * { Point a)}
$$ 7 . 125 _ { 10 } = ( 1 + 2 ^ { - 1 } + 2 ^ { - 2 } + 2 ^ { - 5 } ) * { 2 ^ 2 } _ { 10 } = 0 | 1100 1000 0000 | 110 _ F $$
$$ 0 . 8 _ { 10 } = ( 1 + 2 ^ { - 1 } + 2 ^ { - 4 } + 2 ^ { - 5 } + 2 ^ { - 8 } + 2 ^ { - 9 } + 2 ^ { - 12 } ) * { 2 ^ { - 1 } } _ { 10 } \approx 0 | 100110011001 | 011 _ F $$
$$ 0 . 046875 _ { 10 } = ( 2 ^ { - 2 } + 2 ^ { - 3 } ) * { 2 ^ { - 3 } } _ { 10 } = 0 | 0011 0000 0000 | 000 _ F $$
For the last conversion, we assume that the denormalized mode of this floating point representation implicitly includes an exponent of $ - 3 $ (this makes the first bit in the mantissa of a denormalized number weigh $ 2 ^ { - 3 } $ ). This behaviour is akin to the denormalized implementation of IEEE 754 floating point numbers.
\subsection * { Point b)}
$$ 1 | 011010111000 | 110 _ F = - ( 1 + 2 ^ { - 2 } + 2 ^ { - 3 } + 2 ^ { - 5 } + 2 ^ { - 7 } + 2 ^ { - 8 } + 2 ^ { - 9 } ) * { 2 ^ { 2 } } _ { 10 } \approx
-5.6796875$$
$$ 1 | 101010101010 | 010 _ F = - ( 1 + 2 ^ { - 1 } + 2 ^ { - 3 } + 2 ^ { - 5 } + 2 ^ { - 7 } + 2 ^ { - 9 } + 2 ^ { - 11 } ) * { 2 ^ { - 2 } } _ { 10 } \approx
-0.4166259766$$
\subsection * { Point c)}
$$ 1 | 0000 0000 0000 | 001 _ F = 2 ^ { - 3 } _ { 10 } = 0 . 125 _ { 10 } $$
\subsection * { Point d)}
2020-04-01 21:25:27 +00:00
$$ 1 | 1111 1111 1111 | 111 _ F = $$
$$ = ( 1 + 2 ^ { - 1 } + 2 ^ { - 2 } + 2 ^ { - 3 } + 2 ^ { - 4 } + 2 ^ { - 5 } + 2 ^ { - 6 } + 2 ^ { - 7 } + 2 ^ { - 8 } + 2 ^ { - 9 } + 2 ^ { - 10 } + 2 ^ { - 11 } + 2 ^ { - 12 } ) * { 2 ^ 3 } _ { 10 } = $$
2020-04-01 21:11:45 +00:00
$$ = 15 . 998046875 _ { 10 } $$
\subsection * { Point e)}
With 12 independent binary choices (bits to flip), there are $ 2 ^ { 12 } $ different denormalized numbers in this encoding.
\subsection * { Point f)}
With 12 independent binary choices (bits to flip) and 3 extra bits for the exponent, there are $ 2 ^ { 15 } - 1 $ different denormalized numbers in this encoding. We subtract 1 in order to be consistent with the assumption in point \textit { a)} , since $ 0 . 125 _ { 10 } $ would be representable both as $ 1 | 0000 0000 0000 | 001 _ F $ and
as $ 1 | 1000 0000 0000 | 000 _ F $
\section * { Question 2}
\subsection * { Point a)}
$$ \sqrt [ 3 ] { 1 + x } - 1 = ( \sqrt [ 3 ] { 1 + x } - 1 ) \cdot
\frac { \sqrt [3] { 1 + x} + 1} { \sqrt [3] { 1 + x} + 1} = \frac { \sqrt [3] { (1 + x)^ 2} - 1} { \sqrt [3] { 1 + x} + 1} =
\frac { \sqrt [3] { (1 + x)^ 2} - 1} { \sqrt [3] { 1 + x} + 1} \cdot \frac { \sqrt [3] { (1 + x)^ 2} + 1} { \sqrt [3] { (1 + x)^ 2} + 1} = $$
$$ \frac { ( 1 + x ) \sqrt [ 3 ] { 1 + x } - 1 } { ( \sqrt [ 3 ] { 1 + x } + 1 ) \cdot ( \sqrt [ 3 ] { ( 1 + x ) ^ 2 } + 1 ) } $$
\subsection * { Point b)}
$$ \frac { 1 - cos ( x ) } { sin ( x ) } = \frac { sin ^ 2 ( x ) cos ^ 2 ( x ) - cos ( x ) } { sin ( x ) } \cdot \frac { sin ( x ) } { cos ( x ) } \cdot \frac { cos ( x ) } { sin ( x ) } = ( sin ^ 2 ( x ) cos ( x ) - 1 ) \cdot \frac { cos ( x ) } { sin ( x ) } $$
\subsection * { Point c)}
$$ \frac { 1 } { 1 - \sqrt { x ^ 2 - 1 } } = \frac { x } { x ^ 2 - \sqrt { x ^ 4 - x ^ 2 } } $$
\subsection * { Point d)}
$$ x ^ 3 \cdot \left ( \frac { x } { x ^ 2 - 1 } - \frac { 1 } { x } \right ) = x ^ 3 \cdot \left ( \frac { x ^ 2 - x ^ 2 + 1 } { x ^ 3 - x } \right ) =
\frac { x^ 2} { x^ 2-1} $$
\subsection * { Point e)}
$$ \frac { 1 } { x } - \frac { 1 } { x + 1 } = \frac { x + 1 - x } { x ^ 2 + x } = \frac { 1 } { x ^ 2 + x } $$
\section * { Question 3}
\subsection * { Point a)}
First we point out that:
$$ \lim _ { h \to 0 } \frac { f ( x + h ) - f ( x ) } { h } \stackrel { k : = - h } { = } \lim _ { k \to 0 } \frac { f ( x - ( - k ) ) - f ( x ) } { - k } = $$
$$ = \lim _ { k \to 0 } \frac { f ( x ) - f ( x + k ) } { k } = - \lim _ { h \to 0 } \frac { f ( x ) - f ( x - h ) } { h } $$
Then, we find an equivalent way to represent $ f' ( x ) $ :
$$ f' ( x ) = \lim _ { h \to 0 } \frac { f ( x + h ) - f ( x ) } { h } = 2 \cdot \lim _ { h \to 0 } \frac { f ( x + h ) - f ( x ) } { 2 h } = $$
$$ = \lim _ { h \to 0 } \frac { f ( x + h ) - f ( x ) } { 2 h } + \left ( - \lim _ { h \to 0 } \frac { f ( x ) - f ( x - h ) } { 2 h } \right ) = \lim _ { h \to 0 } \frac { f ( x + h ) - f ( x - h ) } { 2 h } $$
Then we consider the \textit { epsilon-delta} definition of limits for the last limit:
$$ \forall \epsilon > 0 \exists \delta > 0 | \forall h > 0 , \text { if } 0 < h < \delta \Rightarrow $$
$$ \left | \frac { f ( x + h ) - f ( x - h ) } { 2 h } - f' ( x ) \right | = \left |f' ( x ) - \frac { f ( x + h ) - f ( x - h ) } { 2 h } \right | < \epsilon $$
I GIVE UP :(
\section * { Question 4}
\subsection * { Point a)}
\[
A_ 1 =
\begin { bmatrix}
1 & 1 & 1 & 1 & 1 \\
2 & 4 & 4 & 4 & 4 \\
3 & 7 & 10 & 10 & 10 \\
4 & 10 & 16 & 20 & 20 \\
5 & 13 & 22 & 30 & 35 \\
\end { bmatrix} ,
b =
\begin { bmatrix}
1 \\ 2 \\ 3 \\ 4 \\ 5 \\
\end { bmatrix}
\]
\[
l_ 1 =
\begin { bmatrix}
1 \\ 2 \\ 3 \\ 4 \\ 5 \\
\end { bmatrix} ,
u_ 1 =
\begin { bmatrix}
1 & 1 & 1 & 1 & 1 \\
\end { bmatrix} ,
A_ 2
\begin { bmatrix}
0 & 0 & 0 & 0 & 0 \\
0 & 2 & 2 & 2 & 2 \\
0 & 4 & 7 & 7 & 7 \\
0 & 6 & 12 & 16 & 16 \\
0 & 8 & 17 & 25 & 30 \\
\end { bmatrix}
\]
\[
l_ 2 =
\begin { bmatrix}
0 \\ 1 \\ 2 \\ 3 \\ 4 \\
\end { bmatrix} ,
u_ 2 =
\begin { bmatrix}
0 & 2 & 2 & 2 & 2 \\
\end { bmatrix} ,
A_ 3
\begin { bmatrix}
0 & 0 & 0 & 0 & 0 \\
0 & 0 & 0 & 0 & 0 \\
0 & 0 & 3 & 3 & 3 \\
0 & 0 & 6 & 10 & 10 \\
0 & 0 & 9 & 17 & 22 \\
\end { bmatrix}
\]
\[
l_ 3 =
\begin { bmatrix}
0 \\ 0 \\ 1 \\ 2 \\ 3 \\
\end { bmatrix} ,
u_ 3 =
\begin { bmatrix}
0 & 0 & 3 & 3 & 3 \\
\end { bmatrix} ,
A_ 4
\begin { bmatrix}
0 & 0 & 0 & 0 & 0 \\
0 & 0 & 0 & 0 & 0 \\
0 & 0 & 0 & 0 & 0 \\
0 & 0 & 0 & 4 & 4 \\
0 & 0 & 0 & 8 & 13 \\
\end { bmatrix}
\]
\[
l_ 4 =
\begin { bmatrix}
0 \\ 0 \\ 0 \\ 1 \\ 2 \\
\end { bmatrix} ,
u_ 4 =
\begin { bmatrix}
0 & 0 & 0 & 4 & 4 \\
\end { bmatrix} ,
A_ 5
\begin { bmatrix}
0 & 0 & 0 & 0 & 0 \\
0 & 0 & 0 & 0 & 0 \\
0 & 0 & 0 & 0 & 0 \\
0 & 0 & 0 & 0 & 0 \\
0 & 0 & 0 & 0 & 5 \\
\end { bmatrix}
\]
\[
2020-04-01 21:25:27 +00:00
l_ 5 =
2020-04-01 21:11:45 +00:00
\begin { bmatrix}
0 \\ 0 \\ 0 \\ 0 \\ 1 \\
\end { bmatrix} ,
u_ 5 =
\begin { bmatrix}
0 & 0 & 0 & 0 & 5 \\
\end { bmatrix} ,
L =
\begin { bmatrix}
1 & 0 & 0 & 0 & 0 \\
2 & 1 & 0 & 0 & 0 \\
3 & 2 & 1 & 0 & 0 \\
4 & 3 & 2 & 1 & 0 \\
5 & 4 & 3 & 2 & 1 \\
\end { bmatrix} ,
U =
\begin { bmatrix}
1 & 1 & 1 & 1 & 1 \\
0 & 2 & 2 & 2 & 2 \\
0 & 0 & 3 & 3 & 3 \\
0 & 0 & 0 & 4 & 4 \\
0 & 0 & 0 & 0 & 5 \\
\end { bmatrix}
\]
\subsection * { Point b)}
\[
2020-04-01 21:25:27 +00:00
l_ 1 =
2020-04-01 21:11:45 +00:00
\begin { bmatrix}
1 \\ 2 \\ 3 \\ 4 \\ 5 \\
\end { bmatrix} ,
e^ { T} _ 1 =
\begin { bmatrix}
1 & 0 & 0 & 0 & 0 \\
\end { bmatrix} ,
L_ 1 =
\begin { bmatrix}
0 & 0 & 0 & 0 & 0 \\
-2 & 1 & 0 & 0 & 0 \\
-3 & 0 & 1 & 0 & 0 \\
-4 & 0 & 0 & 1 & 0 \\
-5 & 0 & 0 & 0 & 1 \\
\end { bmatrix}
\]
\[
2020-04-01 21:25:27 +00:00
l_ 2 =
2020-04-01 21:11:45 +00:00
\begin { bmatrix}
0 \\ 1 \\ 2 \\ 3 \\ 4 \\
\end { bmatrix} ,
e^ { T} _ 2 =
\begin { bmatrix}
0 & 1 & 0 & 0 & 0 \\
\end { bmatrix} ,
L_ 2 =
\begin { bmatrix}
1 & 0 & 0 & 0 & 0 \\
0 & 0 & 0 & 0 & 0 \\
0 & -2 & 1 & 0 & 0 \\
0 & -3 & 0 & 1 & 0 \\
0 & -4 & 0 & 0 & 1 \\
\end { bmatrix}
\]
\[
2020-04-01 21:25:27 +00:00
l_ 3 =
2020-04-01 21:11:45 +00:00
\begin { bmatrix}
0 \\ 0 \\ 1 \\ 2 \\ 3 \\
\end { bmatrix} ,
e^ { T} _ 3 =
\begin { bmatrix}
0 & 0 & 1 & 0 & 0 \\
\end { bmatrix} ,
L_ 3 =
\begin { bmatrix}
1 & 0 & 0 & 0 & 0 \\
0 & 1 & 0 & 0 & 0 \\
0 & 0 & 0 & 0 & 0 \\
0 & 0 & -2 & 1 & 0 \\
0 & 0 & -3 & 0 & 1 \\
\end { bmatrix}
\]
\[
2020-04-01 21:25:27 +00:00
l_ 4 =
2020-04-01 21:11:45 +00:00
\begin { bmatrix}
0 \\ 0 \\ 0 \\ 1 \\ 2 \\
\end { bmatrix} ,
e^ { T} _ 4 =
\begin { bmatrix}
0 & 0 & 0 & 1 & 0 \\
\end { bmatrix} ,
L_ 4 =
\begin { bmatrix}
1 & 0 & 0 & 0 & 0 \\
0 & 1 & 0 & 0 & 0 \\
0 & 0 & 1 & 0 & 0 \\
0 & 0 & 0 & 0 & 0 \\
0 & 0 & 0 & -2 & 1 \\
\end { bmatrix}
\]
2020-04-01 21:25:27 +00:00
\subsection * { Point c)}
$$ Ly = b $$
\[
L =
\begin { bmatrix}
1 & 0 & 0 & 0 & 0 \\
2 & 1 & 0 & 0 & 0 \\
3 & 2 & 1 & 0 & 0 \\
4 & 3 & 2 & 1 & 0 \\
5 & 4 & 3 & 2 & 1 \\
\end { bmatrix} ,
b =
\begin { bmatrix}
1 \\ 2 \\ 3 \\ 4 \\ 5 \\
\end { bmatrix}
\]
\[
L =
\begin { bmatrix}
1 & 0 & 0 & 0 & 0 \\
2 & 1 & 0 & 0 & 0 \\
3 & 2 & 1 & 0 & 0 \\
4 & 3 & 2 & 1 & 0 \\
5 & 4 & 3 & 2 & 1 \\
\end { bmatrix} ,
b =
\begin { bmatrix}
1 \\ 2 \\ 3 \\ 4 \\ 5 \\
\end { bmatrix}
\]
$$ y _ 1 = \frac { 1 } { 1 } = 1 $$
$$ y _ 2 = \frac { 2 - 2 \cdot 1 } { 1 } = 0 $$
$$ y _ 3 = \frac { 3 - 3 \cdot 1 - 2 \cdot 0 } { 1 } = 0 $$
$$ y _ 4 = \frac { 4 - 4 \cdot 1 - 3 \cdot 0 - 2 \cdot 0 } { 1 } = 0 $$
$$ y _ 5 = \frac { 5 - 5 \cdot 1 - 4 \cdot 0 - 3 \cdot 0 - 2 \cdot 0 } { 1 } = 0 $$
\[
y =
\begin { bmatrix}
1 \\ 0 \\ 0 \\ 0 \\ 0 \\
\end { bmatrix}
\]
\subsection * { Point d)}
$$ Ux = y $$
\[
U =
\begin { bmatrix}
1 & 1 & 1 & 1 & 1 \\
0 & 2 & 2 & 2 & 2 \\
0 & 0 & 3 & 3 & 3 \\
0 & 0 & 0 & 4 & 4 \\
0 & 0 & 0 & 0 & 5 \\
\end { bmatrix}
y =
\begin { bmatrix}
1 \\ 0 \\ 0 \\ 0 \\ 0 \\
\end { bmatrix}
\]
$$ x _ 5 = \frac { 0 } { 5 } = 0 $$
$$ x _ 4 = \frac { 0 - 4 \cdot 0 } { 4 } = 0 $$
$$ x _ 3 = \frac { 0 - 3 \cdot 0 - 3 \cdot 0 } { 3 } = 0 $$
$$ x _ 2 = \frac { 0 - 2 \cdot 0 - 2 \cdot 0 - 2 \cdot 0 } { 2 } = 0 $$
$$ x _ 1 = \frac { 0 - 1 \cdot 0 - 1 \cdot 0 - 1 \cdot 0 - 1 \cdot } { 1 } = 0 $$
\[
x =
\begin { bmatrix}
0 \\ 0 \\ 0 \\ 0 \\ 0 \\
\end { bmatrix}
\]
2020-04-02 21:44:15 +00:00
\section * { Question 5}
\subsection * { Point a)}
$$ f ( x ) = x \hspace { 2 cm } K _ { abs } = |f' ( x ) | = 1 \hspace { 2 cm } K _ { rel } = \left | \frac { 1 \cdot x } { x } \right | = 1 $$
\subsection * { Point b)}
$$ f ( x ) = \sqrt [ 3 ] { x } \hspace { 2 cm } K _ { abs } = |f' ( x ) | = \frac { 1 } { 3 \sqrt [ 3 ] { x ^ 2 } } \hspace { 2 cm }
K_ { rel} = \left |\frac { 1} { 3\sqrt [3] { x^ 2} } \cdot \frac { x} { \sqrt [3] { x} } \right | = \frac { 1} { 3} $$
\subsection * { Point c)}
$$ f ( x ) = \frac { 1 } { x } \hspace { 2 cm } K _ { abs } = |f' ( x ) | = \frac { 1 } { x ^ 2 } \hspace { 2 cm }
K_ { rel} = \left |\frac { -x} { x^ 2} \cdot \frac { 1} { \frac { 1} { x} } \right | = 1$$
\subsection * { Point d)}
$$ f ( x ) = e ^ x \hspace { 2 cm } K _ { abs } = |f' ( x ) | = e ^ x \hspace { 2 cm }
K_ { rel} = \left |\frac { xe^ x} { e^ x} \right | = |x|$$
\subsection * { Point e)}
Cases \textit { a)} ,\textit { b)} and \textit { c)} are well-conditioned for any $ x $ since their $ K _ rel $
is not defined by x. Case \textit { d)} is well-conditioned only for $ x $ s whose absolute value is in the order of magnitude of $ 1 $ or less, since $ K _ rel $ in this case is exactly $ |x| $ .
2020-04-01 21:25:27 +00:00
\end { document}