Newer
Older
Lecture_repo / Lectures_my / NumMet / Lecture1 / mchrzasz.tex
@mchrzasz mchrzasz on 19 Sep 2016 22 KB fixed typos
  1. \documentclass[11 pt,xcolor={dvipsnames,svgnames,x11names,table}]{beamer}
  2.  
  3. \usepackage[english]{babel}
  4. \usepackage{polski}
  5.  
  6.  
  7. \usetheme[
  8. bullet=circle, % Other option: square
  9. bigpagenumber, % circled page number on lower right
  10. topline=true, % colored bar at the top of the frame
  11. shadow=false, % Shading for beamer blocks
  12. watermark=BG_lower, % png file for the watermark
  13. ]{Flip}
  14.  
  15. %\logo{\kern+1.em\includegraphics[height=1cm]{SHiP-3_LightCharcoal}}
  16.  
  17. \usepackage[lf]{berenis}
  18. \usepackage[LY1]{fontenc}
  19. \usepackage[utf8]{inputenc}
  20. \usepackage{cases}
  21. \usepackage{mathtools}
  22. \usepackage{emerald}
  23. \usefonttheme{professionalfonts}
  24. \usepackage[no-math]{fontspec}
  25. \defaultfontfeatures{Mapping=tex-text} % This seems to be important for mapping glyphs properly
  26.  
  27. \setmainfont{Gillius ADF} % Beamer ignores "main font" in favor of sans font
  28. \setsansfont{Gillius ADF} % This is the font that beamer will use by default
  29. % \setmainfont{Gill Sans Light} % Prettier, but harder to read
  30.  
  31. \setbeamerfont{title}{family=\fontspec{Gillius ADF}}
  32.  
  33. \input t1augie.fd
  34.  
  35. %\newcommand{\handwriting}{\fontspec{augie}} % From Emerald City, free font
  36. %\newcommand{\handwriting}{\usefont{T1}{fau}{m}{n}} % From Emerald City, free font
  37. % \newcommand{\handwriting}{} % If you prefer no special handwriting font or don't have augie
  38.  
  39. %% Gill Sans doesn't look very nice when boldfaced
  40. %% This is a hack to use Helvetica instead
  41. %% Usage: \textbf{\forbold some stuff}
  42. %\newcommand{\forbold}{\fontspec{Arial}}
  43.  
  44. \usepackage{graphicx}
  45. \usepackage[export]{adjustbox}
  46.  
  47. \usepackage{amsmath}
  48. \usepackage{amsfonts}
  49. \usepackage{amssymb}
  50. \usepackage{bm}
  51. \usepackage{colortbl}
  52. \usepackage{mathrsfs} % For Weinberg-esque letters
  53. \usepackage{cancel} % For "SUSY-breaking" symbol
  54. \usepackage{slashed} % for slashed characters in math mode
  55. \usepackage{bbm} % for \mathbbm{1} (unit matrix)
  56. \usepackage{amsthm} % For theorem environment
  57. \usepackage{multirow} % For multi row cells in table
  58. \usepackage{arydshln} % For dashed lines in arrays and tables
  59. \usepackage{siunitx}
  60. \usepackage{xhfill}
  61. \usepackage{grffile}
  62. \usepackage{textpos}
  63. \usepackage{subfigure}
  64. \usepackage{tikz}
  65. \usepackage{hyperref}
  66. %\usepackage{hepparticles}
  67. \usepackage[italic]{hepparticles}
  68.  
  69. \usepackage{hepnicenames}
  70.  
  71. % Drawing a line
  72. \tikzstyle{lw} = [line width=20pt]
  73. \newcommand{\topline}{%
  74. \tikz[remember picture,overlay] {%
  75. \draw[crimsonred] ([yshift=-23.5pt]current page.north west)
  76. -- ([yshift=-23.5pt,xshift=\paperwidth]current page.north west);}}
  77.  
  78.  
  79.  
  80. % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
  81. \usepackage{tikzfeynman} % For Feynman diagrams
  82. \usetikzlibrary{arrows,shapes}
  83. \usetikzlibrary{trees}
  84. \usetikzlibrary{matrix,arrows} % For commutative diagram
  85. % http://www.felixl.de/commu.pdf
  86. \usetikzlibrary{positioning} % For "above of=" commands
  87. \usetikzlibrary{calc,through} % For coordinates
  88. \usetikzlibrary{decorations.pathreplacing} % For curly braces
  89. % http://www.math.ucla.edu/~getreuer/tikz.html
  90. \usepackage{pgffor} % For repeating patterns
  91.  
  92. \usetikzlibrary{decorations.pathmorphing} % For Feynman Diagrams
  93. \usetikzlibrary{decorations.markings}
  94. \tikzset{
  95. % >=stealth', %% Uncomment for more conventional arrows
  96. vector/.style={decorate, decoration={snake}, draw},
  97. provector/.style={decorate, decoration={snake,amplitude=2.5pt}, draw},
  98. antivector/.style={decorate, decoration={snake,amplitude=-2.5pt}, draw},
  99. fermion/.style={draw=gray, postaction={decorate},
  100. decoration={markings,mark=at position .55 with {\arrow[draw=gray]{>}}}},
  101. fermionbar/.style={draw=gray, postaction={decorate},
  102. decoration={markings,mark=at position .55 with {\arrow[draw=gray]{<}}}},
  103. fermionnoarrow/.style={draw=gray},
  104. gluon/.style={decorate, draw=black,
  105. decoration={coil,amplitude=4pt, segment length=5pt}},
  106. scalar/.style={dashed,draw=black, postaction={decorate},
  107. decoration={markings,mark=at position .55 with {\arrow[draw=black]{>}}}},
  108. scalarbar/.style={dashed,draw=black, postaction={decorate},
  109. decoration={markings,mark=at position .55 with {\arrow[draw=black]{<}}}},
  110. scalarnoarrow/.style={dashed,draw=black},
  111. electron/.style={draw=black, postaction={decorate},
  112. decoration={markings,mark=at position .55 with {\arrow[draw=black]{>}}}},
  113. bigvector/.style={decorate, decoration={snake,amplitude=4pt}, draw},
  114. }
  115.  
  116. % TIKZ - for block diagrams,
  117. % from http://www.texample.net/tikz/examples/control-system-principles/
  118. % \usetikzlibrary{shapes,arrows}
  119. \tikzstyle{block} = [draw, rectangle,
  120. minimum height=3em, minimum width=6em]
  121.  
  122.  
  123.  
  124.  
  125. \usetikzlibrary{backgrounds}
  126. \usetikzlibrary{mindmap,trees} % For mind map
  127. \newcommand{\degree}{\ensuremath{^\circ}}
  128. \newcommand{\E}{\mathrm{E}}
  129. \newcommand{\Var}{\mathrm{Var}}
  130. \newcommand{\Cov}{\mathrm{Cov}}
  131. \newcommand\Ts{\rule{0pt}{2.6ex}} % Top strut
  132. \newcommand\Bs{\rule[-1.2ex]{0pt}{0pt}} % Bottom strut
  133.  
  134. \graphicspath{{images/}} % Put all images in this directory. Avoids clutter.
  135.  
  136. % SOME COMMANDS THAT I FIND HANDY
  137. % \renewcommand{\tilde}{\widetilde} % dinky tildes look silly, dosn't work with fontspec
  138. \newcommand{\comment}[1]{\textcolor{comment}{\footnotesize{#1}\normalsize}} % comment mild
  139. \newcommand{\Comment}[1]{\textcolor{Comment}{\footnotesize{#1}\normalsize}} % comment bold
  140. \newcommand{\COMMENT}[1]{\textcolor{COMMENT}{\footnotesize{#1}\normalsize}} % comment crazy bold
  141. \newcommand{\Alert}[1]{\textcolor{Alert}{#1}} % louder alert
  142. \newcommand{\ALERT}[1]{\textcolor{ALERT}{#1}} % loudest alert
  143. %% "\alert" is already a beamer pre-defined
  144. \newcommand*{\Scale}[2][4]{\scalebox{#1}{$#2$}}%
  145.  
  146. \def\Put(#1,#2)#3{\leavevmode\makebox(0,0){\put(#1,#2){#3}}}
  147.  
  148. \usepackage{gmp}
  149. \usepackage[final]{feynmp-auto}
  150.  
  151. \usepackage[backend=bibtex,style=numeric-comp,firstinits=true]{biblatex}
  152. \bibliography{bib}
  153. \setbeamertemplate{bibliography item}[text]
  154.  
  155. \makeatletter\let\frametextheight\beamer@frametextheight\makeatother
  156.  
  157. % suppress frame numbering for backup slides
  158. % you always need the appendix for this!
  159. \newcommand{\backupbegin}{
  160. \newcounter{framenumberappendix}
  161. \setcounter{framenumberappendix}{\value{framenumber}}
  162. }
  163. \newcommand{\backupend}{
  164. \addtocounter{framenumberappendix}{-\value{framenumber}}
  165. \addtocounter{framenumber}{\value{framenumberappendix}}
  166. }
  167.  
  168.  
  169. \definecolor{links}{HTML}{2A1B81}
  170. %\hypersetup{colorlinks,linkcolor=,urlcolor=links}
  171.  
  172. % For shapo's formulas:
  173. \def\lsi{\raise0.3ex\hbox{$<$\kern-0.75em\raise-1.1ex\hbox{$\sim$}}}
  174. \def\gsi{\raise0.3ex\hbox{$>$\kern-0.75em\raise-1.1ex\hbox{$\sim$}}}
  175. \newcommand{\lsim}{\mathop{\lsi}}
  176. \newcommand{\gsim}{\mathop{\gsi}}
  177. \newcommand{\wt}{\widetilde}
  178. %\newcommand{\ol}{\overline}
  179. \newcommand{\Tr}{\rm{Tr}}
  180. \newcommand{\tr}{\rm{tr}}
  181. \newcommand{\eqn}[1]{&\hspace{-0.7em}#1\hspace{-0.7em}&}
  182. \newcommand{\vev}[1]{\rm{$\langle #1 \rangle$}}
  183. \newcommand{\abs}[1]{\rm{$\left| #1 \right|$}}
  184. \newcommand{\eV}{\rm{eV}}
  185. \newcommand{\keV}{\rm{keV}}
  186. \newcommand{\GeV}{\rm{GeV}}
  187. \newcommand{\im}{\rm{Im}}
  188. \newcommand{\disp}{\displaystyle}
  189. \def\be{\begin{equation}}
  190. \def\ee{\end{equation}}
  191. \def\ba{\begin{eqnarray}}
  192. \def\ea{\end{eqnarray}}
  193. \def\d{\partial}
  194. \def\l{\left(}
  195. \def\r{\right)}
  196. \def\la{\langle}
  197. \def\ra{\rangle}
  198. \def\e{{\rm e}}
  199. \def\Br{{\rm Br}}
  200. \def\fixme{{\color{red} FIXME!}}
  201. \def\mc{{\color{Magenta}{MC}}\xspace}
  202. \def\pdf{{\rm p.d.f.}}
  203. \def\ARROW{{\color{JungleGreen}{$\Rrightarrow$}}\xspace}
  204. \def\ARROWR{{\color{WildStrawberry}{$\Rrightarrow$}}\xspace}
  205.  
  206. \author{ {\fontspec{Trebuchet MS}Marcin Chrz\k{a}szcz, Danny van Dyk} (UZH)}
  207. \institute{UZH}
  208. \title[Introduction to \\Numerical Methods]{Introduction to \\Numerical Methods}
  209. \date{\fixme}
  210.  
  211.  
  212. \begin{document}
  213. \tikzstyle{every picture}+=[remember picture]
  214.  
  215. {
  216. \setbeamertemplate{sidebar right}{\llap{\includegraphics[width=\paperwidth,height=\paperheight]{bubble2}}}
  217. \begin{frame}[c]%{\phantom{title page}}
  218. \begin{center}
  219. \begin{center}
  220. \begin{columns}
  221. \begin{column}{0.9\textwidth}
  222. \flushright\fontspec{Trebuchet MS}\bfseries \Huge {Introduction to \\numerical Methods}
  223. \end{column}
  224. \begin{column}{0.2\textwidth}
  225. %\includegraphics[width=\textwidth]{SHiP-2}
  226. \end{column}
  227. \end{columns}
  228. \end{center}
  229. \quad
  230. \vspace{3em}
  231. \begin{columns}
  232. \begin{column}{0.6\textwidth}
  233. \flushright \vspace{-1.8em} {\fontspec{Trebuchet MS} \large Marcin Chrząszcz, Danny van Dyk\\\vspace{-0.1em}\small \href{mailto:mchrzasz@cern.ch}{mchrzasz@cern.ch}, \href{mailto:dany.van.dyk@gmail.com}{danny.van.dyk@gmail.com}}
  234.  
  235. \end{column}
  236. \begin{column}{0.4\textwidth}
  237. \includegraphics[height=1.3cm]{uzh-transp}
  238. \end{column}
  239. \end{columns}
  240.  
  241. \vspace{1em}
  242. % \footnotesize\textcolor{gray}{With N. Serra, B. Storaci\\Thanks to the theory support from M. Shaposhnikov, D. Gorbunov}\normalsize\\
  243. \vspace{0.5em}
  244. \textcolor{normal text.fg!50!Comment}{Numerical Methods, \\ 19 September, 2016}
  245. \end{center}
  246. \end{frame}
  247. }
  248.  
  249.  
  250.  
  251. \begin{frame}\frametitle{Course plan}
  252. \begin{small}
  253. \ARROW The course consists of 2 hours lecture and 2 hours of exercise.\\
  254. \ARROW TA will explain to you how you will get points for the class exercise (you will be coding the algorithms) described on the lecture and applying them to some problems.\\
  255. \ARROW After passing the class exercise ($>66\%$ of points) you will have an exam (oral).\\
  256.  
  257.  
  258. \begin{columns}
  259. \column{0.7\textwidth}
  260. \ARROW The final mark:
  261. \vspace{0.1cm}
  262. \begin{footnotesize}
  263. \begin{equation*}
  264. {\rm mark}= 0.5~ {\rm exam} + 0.5 ~ {\rm class}
  265. \end{equation*}
  266. \ARROW The final exam will be average of exam and class marks.
  267. \end{footnotesize}
  268. \column{0.05\textwidth}
  269. {~}
  270. \column{0.25\textwidth}
  271. \begin{footnotesize}
  272.  
  273. \begin{tabular}{|c|c|}
  274. \hline
  275. Mark & Range\\\hline
  276. $6$ & $84-100~\%$ \\
  277. $5$ & $67-83~\%$ \\
  278. $4$ & $50-67~\%$ \\ \hline
  279. $3$ & $33-50~\%$ \\
  280. $2$ & $16-33~\%$ \\
  281. $1$ & $0-16~\%$ \\
  282. \hline
  283. \end{tabular}
  284.  
  285. \end{footnotesize}
  286.  
  287.  
  288. \end{columns}
  289. \end{small}
  290. \end{frame}
  291.  
  292. \begin{frame}\frametitle{Course plan}
  293. \begin{enumerate}
  294. \item Numerical precision, floating point representation.
  295. \item Numerical stability.
  296. \item Function interpolation, multidim. function interpolation.
  297. \item Function approximation.
  298. \item Linear equation solving with elimination methods and iteration methods.
  299. \item Non-linear system of equation solving.
  300. \item Numerical integration.
  301. \item Differential equations solving.
  302. \item Chaos theorem.
  303. \end{enumerate}
  304.  
  305. \end{frame}
  306.  
  307.  
  308. \begin{frame}\frametitle{Why do we need numerical methods?}
  309. \begin{exampleblock}{Prose:}
  310. \ARROWR Most of the problems that one tackles on daily basis cannot be computed analytically! During the university studies the problems you were solving were tailor suited to be analytically solvable!\\
  311. \ARROWR Even if the problem is solvable analytically in daily work one needs to repeat the calculations many times changing some conditions. Solving $n^{\rm th}$ time a similar integral on paper can have deadly consequences on your sanity.\\
  312. \ARROWR Let's face is computers are just much much faster then us in this kind of computations.\\
  313. \end{exampleblock}
  314. \begin{alertblock}{Cons:}
  315. \ARROW One disadvantage of numerical methods is the fact that they don't give you an exact solution. The reason for that is that the computers don't operate on real numbers but just on their representation which we will learn during todays lecture.
  316. \end{alertblock}
  317. \end{frame}
  318.  
  319. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  320. \begin{frame}\frametitle{Errors, fast reminder}
  321. \ARROW As you already know there are two types of errors:
  322. \begin{itemize}
  323. \item Absolute error $\Delta$.
  324. \item Relative error $\delta$.
  325. \end{itemize}
  326.  
  327. \begin{align*}
  328. \Delta = \vert A - a \vert~~~~~~~~~~~\delta = \vert \frac{A- a}{A} \vert, ~~A \neq 0,
  329. \end{align*}
  330. where $A$ is the exact number, $a$ its approximation.\\ \pause
  331. \ARROW Now since we know what are errors lets look into the sources of errors:\\
  332. \ARROWR Input errors.\\
  333. \ARROWR Cut-off errors.\\
  334. \ARROWR Rounding errors.
  335.  
  336.  
  337. \end{frame}
  338.  
  339. \begin{frame}\frametitle{Input Errors}
  340. \begin{small}
  341.  
  342.  
  343. \ARROW Input errors are errors that are associated with the inputs to the computer. We can have different types of this errors:
  344. \begin{columns}
  345. \column{0.6\textwidth}
  346. \begin{itemize}
  347. \item Mathematical model errors. A canonical example of such simplification is the pendulum, where we make an approximation of $\sin x =x$ for small $x$:
  348. \begin{align*}
  349. l \frac{d^2x}{dt^2} + g x =0
  350. \end{align*}
  351. \item Errors associated to a given numerical algorithm: a choice of a numerical algorithm is indeed an very important step of solving a given problem. As we will see during the course the simplest models that are fast to implement to execute on the machine can lead to large numerical errors.
  352. \end{itemize}
  353.  
  354.  
  355. \column{0.4\textwidth}
  356. \includegraphics[width=0.75\textwidth]{images/pen.jpg}
  357.  
  358. \begin{itemize}
  359. \item Input data errors. For many computations one needs tome inputs: constants, starting points, etc. There are errors that are associated to those as well. This kind of errors are super the easiest to control and usually are negligible.
  360.  
  361. \end{itemize}
  362.  
  363. \end{columns}
  364.  
  365. \end{small}
  366.  
  367. \end{frame}
  368.  
  369.  
  370.  
  371. \begin{frame}\frametitle{Cut-off Errors}
  372. \begin{small}
  373. \ARROW This kind of errors arise where the true mathematical problem have some kind of infinite sum.\\
  374. \ARROWR Computers are stupid creatures and they don't understand what is $\infty$ so we need to cut of computations at some point. Example:
  375. \begin{exampleblock}{Maclaurin series:}
  376. We know that an $e^x$ function can be Taylor expanded:
  377. \begin{align*}
  378. e^x = \sum_{n=0}^{n=\infty} \frac{x^n}{n!}=1 +x +\frac{x^2}{2!} + \frac{x^3}{3!}+\frac{x^4}{4!}+...
  379. \end{align*}
  380. We can replace the infinite sum with a finite one:
  381. \begin{align*}
  382. e^x \approx =1 +x +\frac{x^2}{2!} + \frac{x^3}{3!}+\frac{x^4}{4!}+...+\frac{x^N}{N!}
  383. \end{align*}
  384.  
  385.  
  386. \end{exampleblock}
  387. \ARROW This kind of errors are unfortunately very common in the field. We will have to deal with them every time we have some kind of $\lim$, $\sum^{\infty}$, etc.
  388.  
  389.  
  390. \end{small}
  391.  
  392. \end{frame}
  393.  
  394.  
  395. \begin{frame}\frametitle{Rounding Errors}
  396. \begin{small}
  397. \ARROW This kind of errors occur during calculations on machines.\\
  398. \ARROW Machine represents the number with a final precision.\\
  399. \ARROW During the calculations the errors accumulate with every operation.\\
  400. \ARROW This errors can be avoided or reduced by proper algorithm or by changing the precision of computations.
  401. \pause
  402. \begin{center}
  403. \includegraphics[width=0.8\textwidth]{images/prec.png}
  404.  
  405. \end{center}
  406.  
  407.  
  408. \end{small}
  409.  
  410. \end{frame}
  411.  
  412.  
  413. \begin{frame}\frametitle{Integer numbers on our PC}
  414. \begin{small}
  415. \ARROW The integer numbers are very easy to represent on PC:
  416. \begin{align*}
  417. a=\pm (c_1N^0 + c_2N^1 +...+ c_dN^{d-1}),
  418. \end{align*}
  419. where $N$ is the base of the system. Computers of course use $2$.
  420. \begin{columns}
  421. \column{3in}
  422. \ARROW For example:
  423. \begin{align*}
  424. 101011 \rightleftarrows & 1 \cdot 2^0 + 1 \cdot 2^1 +0 \cdot 2^2 + 1 \cdot 2^3 +\\ & 0 \cdot 2^4 +1 \cdot 2^5\\ & = 43
  425. \end{align*}
  426. \ARROW Now the first bit can be used for sign determination ($0$ plus $1$ minus) \texttt{int} or can be used to extend the range of numbers \texttt{unsigned}\\
  427. \ARROW \texttt{int} - $-2147483648 - 2147483647$\\
  428. \ARROW \texttt{unsigned} - $0 - 4294967295$
  429.  
  430.  
  431. \column{2in}
  432. \includegraphics[width=0.95\textwidth]{images/joke.jpg}
  433.  
  434. \end{columns}
  435.  
  436. \end{small}
  437.  
  438. \end{frame}
  439.  
  440.  
  441.  
  442. \begin{frame}\frametitle{Floating numbers on our PC}
  443. \begin{small}
  444. \ARROW Computers are using so-called ''classical floating point representation'':
  445. \begin{align*}
  446. a=\pm M \cdot N^C,~a \neq 0,
  447. \end{align*}
  448. \begin{itemize}
  449. \item $M$ - mantissa or significand
  450. \item $N$ - base of the system
  451. \item $C$ - exponent
  452. \end{itemize}
  453. \ARROW In such system the mantissa is always normalized:
  454. \begin{align*}
  455. M \in \left[ \frac{1}{N}, 1 \right)
  456. \end{align*}
  457. \ARROW Using the definition we can write the mantissa and exponent in the following way:
  458. \begin{align*}
  459. M=(m_1N^{-1}+m_2N^{-2}+...+m_t N^{-t})\\
  460. C=\pm(c_1 N^0+ c_2 N^1 + c_3 N^2 + ...+c_d N^{d-1})
  461. \end{align*}
  462. \ARROW The most often know base are $2,8,10,16$.
  463. \end{small}
  464.  
  465. \end{frame}
  466.  
  467. \begin{frame}\frametitle{Numbers on our PC: binary system }
  468. \begin{small}
  469. \ARROW For example let's construct numbers using binary system:
  470. \begin{align*}
  471. M=\pm(m_1 2^{-1}+m_2 2^{-2}+...+m_t 2^t)\\
  472. C=\pm(c_1 2^0+ c_2 2^1 + c_3 2^2 + ...+c_d 2^{d-1})
  473. \end{align*}
  474. where:
  475. \begin{itemize}
  476. \item $t$ - length of mantissa, $d$ - length of exponent
  477. \item $m_i$ - mantissa digits; $m_i \in \lbrace 0,1\rbrace$
  478. \item $c_i$ - exponent digits; $c_i \in \lbrace 0,1\rbrace$
  479. \end{itemize}
  480. \begin{exampleblock}{Example: $11110001~(s)mmmm(s)cc$}
  481. Lets say we are representing a number with a byte. First 5 digits are the mantissa the next 3 are exponent.
  482. \begin{align*}
  483. M=-(1 \cdot 2^{-1} + 1 \cdot 2^{-2} + 1 \cdot 2^{-3} + 0 \cdot 2^{-4} = -\frac{7}{8}\\
  484. C= + (0 \cdot 2^0 + 1 \cdot 2^1)=2\\
  485. x=-\frac{7}{8} \cdot 2^2=-3.5
  486. \end{align*}
  487.  
  488. \end{exampleblock}
  489.  
  490. \end{small}
  491.  
  492. \end{frame}
  493.  
  494.  
  495. \begin{frame}\frametitle{IEEE754-2008}
  496. \begin{small}
  497. \ARROW The rules of the binary systems are defined by the \texttt{ISO-IEEE754} standard (updated in 2008 of the 1985 standard).
  498.  
  499. \begin{center}
  500. \includegraphics[width=0.9\textwidth]{images/table.png}
  501. \end{center}
  502. \ARROW There is a minimum and maximum number we can represent in the current system.\\
  503. \ARROW There are some tricks you can play: use subnormal \\
  504. \ARROW In general we can represent numbers from: $\langle -a, -b \rangle \cup \lbrace 0 \rbrace \cup \langle b,a \rangle$\\
  505. \ARROW The standard also defines the rounding procedures for numbers.
  506.  
  507. \end{small}
  508.  
  509. \end{frame}
  510.  
  511. \begin{frame}\frametitle{Error propagation: sum}
  512. \begin{small}
  513. \ARROW Let's consider we have two numbers $x$ and $y$. \\
  514. \ARROW Their representation are not exact so: $x=\overline{x} + \epsilon_x$ and $y=\overline{y}+\epsilon_y$\\
  515. \ARROW Now if we want to sum them:
  516. \begin{align*}
  517. x+y=\overline{x}+\overline{y} + \epsilon_x+\epsilon_y=\overline{x}+\overline{y}+\epsilon
  518. \end{align*}
  519. \ARROW If each of the $\epsilon_i$ numbers have a constant distribution on $\left[-\frac{1}{2} 10^{-d}, \frac{1}{2} 10^{-d} \right]$, where $d$ is the precision.\\
  520. \ARROW Then $\epsilon$ has a triangular distribution on $\left[-10^{-d}, 10^{-d} \right]$\\
  521. \ARROW Repeating $N$ times this we will approach the Gaussian distribution with a width of $\sim \sqrt{N} 10^{-d}$
  522.  
  523. \end{small}
  524.  
  525. \end{frame}
  526.  
  527. \begin{frame}\frametitle{Error propagation: multiplication, division}
  528. \begin{small}
  529. \ARROW Let's consider we have two numbers $x$ and $y$. \\
  530. \ARROW Their representation are not exact so: $x=\overline{x} + \epsilon_x$ and $y=\overline{y}+\epsilon_y$\\
  531. \ARROW Now if we want to multiply them (we can neglect $\epsilon_x \epsilon_y$ terms):
  532. \begin{align*}
  533. x \cdot y=\overline{x} \cdot \overline{y} + \epsilon_x \cdot \overline{y}+\epsilon_y \cdot \overline{x}
  534. \end{align*}
  535. \ARROW If $\vert \overline{x} \vert \gg (\ll) \vert \overline{y} \vert$ then the error might explode. \\
  536.  
  537. \ARROW Now if we want to divide them:
  538. \begin{align*}
  539. x / y=\overline{x} / \overline{y} + \frac{\epsilon_x}{\overline{y}}+ \frac{\epsilon_y \overline{x}}{\overline{y}^{ {\color{red} 2}}}
  540. \end{align*}
  541.  
  542. \ARROW If $\vert y \vert \ll \vert x \vert$ then the division is will have large errors.
  543. \end{small}
  544.  
  545. \end{frame}
  546.  
  547.  
  548. \begin{frame}\frametitle{Application}
  549. \begin{small}
  550. \ARROW When we implement a current algorithm we need to ensure that our algorithm is ''backward stable'', ''well-conditioned'' and ''numerically stable''.\\
  551. \begin{exampleblock}{Numerical stability}
  552. We say that the algorithm is numerically stable if the the results does not change if we increase the computation precision.
  553.  
  554. \end{exampleblock}
  555. \begin{alertblock}{Backward stability}
  556. Backward stability means that our algorithm will gives us the true answer if we move to infinite precision of the machine. In practice we look if we can conserve the errors of the representation.
  557. \end{alertblock}
  558. \begin{exampleblock}{Well-conditioned}
  559. Each algorithm has some input parameters. If we introduce a slight difference in those parameters (of the order of the representation precision), the results should not change significantly.
  560.  
  561. \end{exampleblock}
  562. \ARROWR The numerical precision lead to discovery of chaos. If we have time we will discuss this during our lectures.
  563.  
  564. \end{small}
  565.  
  566. \end{frame}
  567. \begin{frame}\frametitle{Rounding error}
  568. \begin{small}
  569. \ARROW Imagine we want to calculate:
  570. \begin{align*}
  571. 1.0000+\sum_{i=1}^{10} 0.0001
  572. \end{align*}
  573. \ARROW Now imagine we will carry the calculations with $4$ digit precision.\\
  574. \ARROW If we calculate the:
  575. \begin{align*}
  576. 1.0000+\sum_{i=1}^{10} 0.0001=1.000
  577. \end{align*}
  578. \ARROW If we calculate the:
  579. \begin{align*}
  580. \sum_{i=1}^{10}0.0001+1.0000=1.001
  581. \end{align*}
  582. \ARROW The order matters!
  583. \end{small}
  584.  
  585. \end{frame}
  586.  
  587.  
  588. \begin{frame}\frametitle{Condition parameter}
  589. \begin{small}
  590.  
  591. \begin{exampleblock}{The condition parameter}
  592. \ARROWR Let $\phi : \mathcal{R}^n \to \mathcal{R}^m$ be a function and $x \in \mathcal{R}^n$ be a precise value and $\overline{x} \in \mathcal{R}^n$ its computer representation.\\
  593. \ARROWR If there $\kappa \in \mathcal{R}$ exists that:
  594. \begin{align*}
  595. \forall_{x,\overline{x}}: \frac{\Vert \psi(x)- \psi(\overline{x} \Vert}{\Vert \psi(x) \Vert} \leq \kappa \frac{\Vert x- \overline{x} \Vert}{ \Vert x \Vert}
  596. \end{align*}
  597. \ARROWR The $\kappa$ is called the condition parameter.
  598. \end{exampleblock}
  599.  
  600. \ARROW If the value of $\kappa$ is large then small difference cause by computer representation will explode in the final result.
  601.  
  602.  
  603. \end{small}
  604. \end{frame}
  605.  
  606.  
  607.  
  608. \begin{frame}\frametitle{Examples 1}
  609. \begin{small}
  610. \ARROW Let's calculate the $\pi$ number accordingly to the following formula for couple of $i$:
  611. \begin{align*}
  612. G_p=\frac{1}{p}\left[ 10^p \left(1+p\pi 10^{-p} \right) - 10^p \right]
  613. \end{align*}
  614. with a simple program one can see:
  615. \begin{center}
  616. \includegraphics[width=0.5\textwidth]{images/ex1.png}
  617. \end{center}
  618.  
  619.  
  620. \end{small}
  621.  
  622. \end{frame}
  623.  
  624.  
  625.  
  626. \begin{frame}\frametitle{Example 1}
  627. \begin{small}
  628. \ARROWR How to fix this?!\\
  629. \ARROW Change \texttt{double} to \texttt{long double}
  630.  
  631. \begin{center}
  632. \includegraphics[width=0.5\textwidth]{images/ex2.png}
  633. \end{center}
  634.  
  635.  
  636. \end{small}
  637.  
  638. \end{frame}
  639.  
  640.  
  641.  
  642.  
  643.  
  644. \begin{frame}\frametitle{Example 2}
  645. \begin{small}
  646.  
  647.  
  648.  
  649. \begin{columns}
  650. \column{2.5in}
  651. \begin{align*}
  652. \begin{cases}
  653. x + 3y = 4 \\
  654. x + 3.00001y = 4.00001
  655. \end{cases}
  656. \end{align*}
  657.  
  658.  
  659. \column{2.5in}
  660.  
  661. \begin{align*}
  662. \begin{cases}
  663. x + 3y = 4 \\
  664. x + 2.99999y = 4.00002
  665. \end{cases}
  666. \end{align*}
  667.  
  668.  
  669.  
  670. \end{columns}
  671. {~}\\{~}\\
  672.  
  673. \ARROW The coefficients of this equations are different by maximum of $0.00002$.\\
  674. \ARROW The solutions to the first one is $(1,1)$ and to the second $(10,-2)$. \\
  675. \ARROW So clearly we have a big $\kappa$ as changes $\mathcal{O}(10^{-5})$ are causing differences of $\mathcal{O}(10)$.
  676.  
  677.  
  678. \end{small}
  679.  
  680. \end{frame}
  681.  
  682.  
  683.  
  684.  
  685. \begin{frame}\frametitle{Summary}
  686. \begin{small}
  687.  
  688. \ARROW Computers use only representations of the floating points!\\
  689. \ARROW Numerical methods suffer from computer precision!\\
  690. \ARROW It's YOUR responsibility to ensure that what you are doing will not explode the error.\\
  691.  
  692.  
  693.  
  694. \end{small}
  695.  
  696. \end{frame}
  697.  
  698.  
  699. \backupbegin
  700.  
  701. \begin{frame}\frametitle{Backup}
  702.  
  703.  
  704. \end{frame}
  705.  
  706.  
  707.  
  708.  
  709. \backupend
  710. \end{document}