diff --git a/hw2/hw2.pdf b/hw2/hw2.pdf index 9fce7c8..d625ddb 100644 Binary files a/hw2/hw2.pdf and b/hw2/hw2.pdf differ diff --git a/hw2/hw2.tex b/hw2/hw2.tex index 5bfdef9..8d6d6b6 100644 --- a/hw2/hw2.tex +++ b/hw2/hw2.tex @@ -1,66 +1,90 @@ +% vim: set ts=2 sw=2 et tw=80: + \documentclass[12pt,a4paper]{article} -\usepackage[utf8]{inputenc} -\usepackage[margin=2cm]{geometry} -\usepackage{amstext} -\usepackage{array} +\usepackage[utf8]{inputenc} \usepackage[margin=2cm]{geometry} +\usepackage{amstext} \usepackage{amsmath} \usepackage{array} +\newcommand{\lra}{\Leftrightarrow} \title{Howework 2 -- Introduction to Computational Science} + \author{Claudio Maggioni} -\begin{document} -\maketitle -\section*{Question 1} -The solutions assume that the sign bit $1$ is negative and $0$ is positive. +\begin{document} \maketitle \section*{Question 1} The solutions assume that the +sign bit $1$ is negative and $0$ is positive. -\subsection*{Point a} -\begin{itemize} -\item 13 is equal to $0 1010 0000 000 1011$; -\item 42.125 is equal to $0 0101 0001 000 1101$; -\item 0.8 is equal to $0 1 1001 1001 100 0011$. 0.78 is approximated to 0.7998046875; -\end{itemize} +\subsection*{Point a} \begin{itemize} \item 13 is equal to $0 1010 0000 000 +1011$; \item 42.125 is equal to $0 0101 0001 000 1101$; \item 0.8 is equal to $0 +1 1001 1001 100 0011$. 0.78 is approximated to 0.7998046875; \end{itemize} -\subsection*{Point b} -$1 0110 1011 100 1101$ is $(-1) * (0.25+0.125+0.03125+0.0078125+0.00320625+0.001953125) *2^5$, -which is equal to $-13.4151$. +\subsection*{Point b} $1 0110 1011 100 1101$ is $(-1) * +(0.25+0.125+0.03125+0.0078125+0.00320625+0.001953125) *2^5$, which is equal to +$-13.4151$. + +\subsection*{Point c} $x_{max}$ is $0 1111 1111 111 1111$, equal to $255.9375$. +Since denormalized numbers do not belong to this representation (since the +exponent $0000$ cannot be used for valid numbers other than 0) $x_{min}$ is $0 +0000 0000 000 0001$, equal to $0.0078125$. + +\section*{Question 2} \subsection*{Point a} $$\frac{(x + \Delta x) + (y + \Delta +y) - (x + y)}{x + y} = \frac{\Delta x}{x + y} + \frac{\Delta y}{x + y} = +\frac{x}{x + y}\frac{\Delta x}{x} + \frac{y}{x + y}\frac{\Delta y}{y}$$ + +\subsection*{Point b} $$\frac{(x + \Delta x) - (y + \Delta y) - (x - y)}{x - y} += \frac{\Delta x}{x - y} - \frac{\Delta y}{x - y} = \frac{x}{x - y}\frac{\Delta +x}{x} - \frac{y}{x - y}\frac{\Delta y}{y}$$ + +\subsection*{Point c} $$\frac{((x + \Delta x) (y + \Delta y)) - (x y)}{x y} = +\frac{y \Delta x + x \Delta y + \Delta x \Delta y}{x y} \approx \frac{y \Delta x ++ x \Delta y}{x y} = \frac{\Delta x}{y} + \frac{\Delta y}{x}$$ + +\subsection*{Point d} $$\frac{((x + \Delta x) / (y + \Delta y)) - (x / y)}{x / +y} = \frac{\frac{(x + \Delta x) y}{(y + \Delta y) y} - \frac{(y + \Delta y)x}{(y ++ \Delta y)y}}{x / y} = \frac{y \Delta x - x \Delta y}{x (y + \Delta y)} = +\frac{y \Delta x}{x(y + \Delta y)} - \frac{\Delta y}{y + \Delta y} = $$ $$ = +\left(\frac{x(y + \Delta y)}{y \Delta x}\right)^{-1} - \left(\frac{y + \Delta +y}{\Delta y}\right)^{-1} = \left(\frac{x}{\Delta x} - \frac{y \Delta x}{x \Delta +y}\right)^{-1} - \left(\frac{y}{\Delta y} + 1\right)^{-1} = $$ $$ = +\left(\frac{x}{\Delta x} \left(1 - \frac{\Delta y}{y}\right)\right)^{-1} - +\left(\frac{y}{\Delta y} + 1\right)^{-1} \approx \left(\frac{x}{\Delta +x}\right)^{-1} - \left(\frac{y}{\Delta y}\right)^{-1} = \frac{\Delta x}{x} - +\frac{\Delta y}{y} $$ + +\subsection*{Point e} Division and multiplication may suffer from cancellation. + +\section*{Exercise 3} \subsection*{Point d} The error at first keeps getting +exponentially smaller due to a better approximation of $h$ when computing the +derivative (i.e. $h$ is exponentially nearer to 0), but at $10^{-9}$ this trend +almost becomes the opposite due to loss of significant digits when subtracting +from $e^{x+h}$ $e^x$ and amplifiying this error by effectively multiplying that +with exponentially increasing powers of 10. + +\section*{Exercise 4} \subsection*{Point a} $$||A||_\infty = \max_{1 \leq j \leq +2}{\sum_{j=1}^{2} |a_{i,j}|} = \max{\{5_{j=1}, 2.5_{j=2}\}} = 5$$ $$||A||_1 = +\max_{1 \leq i \leq 2}{\sum_{i=1}^{2} |a_{i,j}|} = \max{\{3.5_{i=1}, 4_{i=2}\}} += 4$$ $$||A||_F = \left(\sum_{i=1}^{2}\sum_{j=1}^{2} +(a_{i,j})^2\right)^{\frac{1}{2}} = (4 + 9 + 2.25 + 1)^{\frac{1}{2}} \approx +4.031$$ + +\subsection*{Point b} $$||B||_\infty = \max_{1 \leq j \leq 3}{\sum_{j=1}^{3} +|b_{i,j}|} = \max{\{12_{j=1}, 6_{j=2}, 3_{j=3}\}} = 12$$ $$||B||_1 = \max_{1 +\leq i \leq 3}{\sum_{i=1}^{3} |b_{i,j}|} = \max{\{9_{i=1}, 7_{i=2}, 5_{i=3}\}} = +9$$ $$||B||_F = \left(\sum_{i=1}^{3}\sum_{j=1}^{3} +(b_{i,j})^2\right)^{\frac{1}{2}} = (36 + 16 + 4 + 1 + 4 + 9 + 4 + 1 + +0)^{\frac{1}{2}} \approx 8.660$$ \subsection*{Point c} -$x_{max}$ is $0 1111 1111 111 1111$, equal to $255.9375$. Since denormalized numbers do not -belong to this representation (since the exponent $0000$ cannot be used for valid numbers other -than 0) $x_{min}$ is $0 0000 0000 000 0001$, equal to $0.0078125$. -\section*{Question 2} -\subsection*{Point a} -$$\frac{(x + \Delta x) + (y + \Delta y) - (x + y)}{x + y} = \frac{\Delta x}{x + y} + \frac{\Delta y}{x + y} = \frac{x}{x + y}\frac{\Delta x}{x} + -\frac{y}{x + y}\frac{\Delta y}{y}$$ +\[ C= \begin{bmatrix} 2 & 3 \\ 1.5 & -1 \\ \end{bmatrix} \begin{bmatrix} 2 & 1.5 + \\ 3 & -1 \\ \end{bmatrix} = \begin{bmatrix} 4 + 9 & 3 - 3 \\ 3 - 3 & 2.25 + 1 + \\ \end{bmatrix} = \begin{bmatrix} 13 & 0 \\ 0 & 3.25 \\ \end{bmatrix} \] -\subsection*{Point b} -$$\frac{(x + \Delta x) - (y + \Delta y) - (x - y)}{x - y} = \frac{\Delta x}{x - y} - \frac{\Delta y}{x - y} = \frac{x}{x - y}\frac{\Delta x}{x} - -\frac{y}{x - y}\frac{\Delta y}{y}$$ +\[ det(C - \lambda i) = det\left( \begin{bmatrix} 13 - \lambda & 0 \\ 0 & 3.25 - +\lambda\\ \end{bmatrix} \right) = (42.25 - 13 \lambda -3.25 \lambda + \lambda^2) +\\ = \lambda^2 - 16.25 \lambda + 42.25 \] -\subsection*{Point c} -$$\frac{((x + \Delta x) (y + \Delta y)) - (x y)}{x y} = \frac{y \Delta x + x \Delta y + \Delta x \Delta y}{x y} \approx -\frac{y \Delta x + x \Delta y}{x y} = \frac{\Delta x}{y} + \frac{\Delta y}{x}$$ +$$det(C - \lambda i) = 0 \lra = \lambda^2 - 16.25 \lambda + 42.25 = 0 \lra +\lambda = 3.25 \lor \lambda = 13$$ -\subsection*{Point d} -$$\frac{((x + \Delta x) / (y + \Delta y)) - (x / y)}{x / y} -= \frac{\frac{(x + \Delta x) y}{(y + \Delta y) y} - \frac{(y + \Delta y)x}{(y + \Delta y)y}}{x / y} -= \frac{y \Delta x - x \Delta y}{x (y + \Delta y)} -= \frac{y \Delta x}{x(y + \Delta y)} - \frac{\Delta y}{y + \Delta y} = $$ -$$ = \left(\frac{x(y + \Delta y)}{y \Delta x}\right)^{-1} - \left(\frac{y + \Delta y}{\Delta y}\right)^{-1} -= \left(\frac{x}{\Delta x} - \frac{y \Delta x}{x \Delta y}\right)^{-1} - \left(\frac{y}{\Delta y} + 1\right)^{-1} = $$ -$$ = \left(\frac{x}{\Delta x} \left(1 - \frac{\Delta y}{y}\right)\right)^{-1} - \left(\frac{y}{\Delta y} + 1\right)^{-1} -\approx \left(\frac{x}{\Delta x}\right)^{-1} - \left(\frac{y}{\Delta y}\right)^{-1} -= \frac{\Delta x}{x} - \frac{\Delta y}{y} -$$ - -\subsection*{Point e} -Division and multiplication may suffer from cancellation. - -\section*{Exercise 3} -\subsection*{Point d} -The error at first keeps getting exponentially smaller due to a better approximation of $h$ when computing the derivative -(i.e. $h$ is exponentially nearer to 0), but at $10^{-9}$ this trend almost becomes the opposite due to loss of significant -digits when subtracting from $e^{x+h}$ $e^x$ and amplifiying this error by effectively multiplying that with exponentially -increasing powers of 10. +$$||A||_2 = \sqrt{\lambda_{max}(AA^T)} = \sqrt{13} \approx 3.606$$ \end{document}