This repository has been archived on 2021-03-28. You can view files and clone it, but cannot push or open issues or pull requests.
ICS/hw1/hw1.tex

66 lines
3 KiB
TeX
Raw Normal View History

2020-03-03 20:54:16 +00:00
\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[margin=2cm]{geometry}
\usepackage{amstext}
\usepackage{array}
\newcolumntype{L}{>{$}l<{$}}
\title{Howework 1 -- Introduction to Computational Science}
\author{Claudio Maggioni}
\begin{document}
\maketitle
\section*{Question 5}
\subsection*{Point a)}
$1.1110_2 * 2^4$, so $d_0=1$, $d_1=1$, $d_2=1$, $d_3=1$, $d_4=0$, and $e=4$.
\subsection*{Point b)}
$1.1110_2 * 2^1$, so $d_0=1$, $d_1=1$, $d_2=1$, $d_3=1$, $d_4=0$, and $e=1$.
\subsection*{Point c)}
$0.00048828125$, or $2^{-4} * 2^{-7}$
\subsection*{Point d)}
$248$, or $(2 - 2^{-4}) * 2^7$
\subsection*{Point e)}
The best approximation for 30.1 is 30, or $1.1110_2 * 2^4$, so $d_0=1$, $d_1=1$, $d_2=1$, $d_3=1$, $d_4=0$, and $e=4$.
This representation is not exact. The number 30.1 cannot be represented exactly in this format or any format with $e=2$.
\section*{Question 6}
\subsection*{Point a)}
$$f(x) = \frac{1}{x} - \frac{1}{x + 1} = \frac{x + 1}{x (x + 1)} - \frac{x}{x (x + 1)}
= \frac{x + 1 - x}{x (x + 1)} = \frac{1}{x (x + 1)} = g(x) $$
\subsection*{Point b)}
$$ f(10_f) = \frac{1}{1.00 * 10^1} - \frac{1}{(1.00 * 10^1) + 1} =
(1.00 * 10^{-1}) - \frac{1}{1.10 * 10^1} \approx$$
$$\approx (1.00 * 10^{-1}) - (0.91 * 10^{-1}) = 9.00 * 10^{-3} = 0.009 $$
$$ g(10_f) = \frac{1}{(1.00 * 10^1) ((1.00 * 10^1) + 1)} = \frac{1}{1.00 * 10^1 * 1.10 * 10^1} \approx
(9.09 * 10^{-3}) = 0.00909$$
$$ f(100_f) = \frac{1}{1.00 * 10^2} - \frac{1}{(1.00 * 10^2) + 1} =
(1.00 * 10^{-2}) - \frac{1}{1.01 * 10^2} \approx$$
$$\approx (1.00 * 10^{-2}) - (0.99 * 10^{-2}) = 1.00 * 10^{-4} = 0.0001 $$
$$ g(100_f) = \frac{1}{(1.00 * 10^2) ((1.00 * 10^2) + 1)} = \frac{1}{1.00 * 10^2 * 1.01 * 10^2} \approx
(0.99 * 10^{-4}) = 0.000099$$
2020-03-04 08:09:11 +00:00
2020-03-03 20:54:16 +00:00
$$ f(1000_f) = \frac{1}{1.00 * 10^3} - \frac{1}{(1.00 * 10^3) + 1} \approx
(1.00 * 10^{-3}) - \frac{1}{1.00 * 10^3} =$$
$$= (1.00 * 10^{-3}) - (1.00 * 10^{-3}) = 0 $$
$$ g(1000_f) = \frac{1}{(1.00 * 10^3) ((1.00 * 10^3) + 1)} \approx \frac{1}{1.00 * 10^3 * 1.00 * 10^3} =
(1.00 * 10^{-6}) = 0.000001$$
\subsection*{Point c)}
\begin{tabular}{L | L | L | L}
\text{Value} & \text{Correct} & \text{Abs. Error} & \text{Rel. error} \\
f(10_f) & 0.\overline{90} & 9.\overline{09} * 10^{-5} & 8.2645 * 10^{-7} \\
g(10_f) & 0.\overline{90} & 9.\overline{09} * 10^{-7} & 8.26 * 10^{-9} \\
f(100_f) & 9.\overline{9009} * 10^{-5} & 9.901 * 10^{-7} & 10^{-2} \\
g(100_f) & 9.\overline{9009} * 10^{-5} & 9.9 * 10^{-9} & 10^{-4} \\
f(1000_f) & 9.99 * 10^{-7} & 9.99 * 10^{-7} & 1 \\
2020-03-04 08:09:11 +00:00
g(1000_f) & 9.99 * 10^{-7} & 10^{-9} & 10^{-3} \\
2020-03-03 20:54:16 +00:00
\end{tabular}
2020-03-04 08:09:11 +00:00
\subsection*{Point d)}
$f(x)$ is clearly less accuratee than $g(x)$ when dealing with floating point numbers. This is largely due to the final
subtraction, since that amplifies approximation errors already introduced in the division $\frac{1}{x + 1}$. Also, the multiplication
in $\frac{1}{x (x + 1)}$ does not cause any approximation errors with the numbers tested, since the mantissa is always 1 and
the multiplication of the exponent part is always exact.
2020-03-03 20:54:16 +00:00
\end{document}