% vim: set sts=4 et : \documentclass[11 pt,xcolor={dvipsnames,svgnames,x11names,table}]{beamer} \usetheme[ bullet=circle, % Other option: square bigpagenumber, % circled page number on lower right topline=true, % colored bar at the top of the frame shadow=false, % Shading for beamer blocks watermark=BG_lower, % png file for the watermark ]{Flip} \usepackage{bm} \usepackage{tikz,pgfplots} \usepgfplotslibrary{fillbetween} \usepackage{graphicx} % SOME COMMANDS THAT I FIND HANDY % \renewcommand{\tilde}{\widetilde} % dinky tildes look silly, dosn't work with fontspec \newcommand{\comment}[1]{\textcolor{comment}{\footnotesize{#1}\normalsize}} % comment mild \newcommand{\Comment}[1]{\textcolor{Comment}{\footnotesize{#1}\normalsize}} % comment bold \newcommand{\COMMENT}[1]{\textcolor{COMMENT}{\footnotesize{#1}\normalsize}} % comment crazy bold \newcommand{\Alert}[1]{\textcolor{Alert}{#1}} % louder alert \newcommand{\ALERT}[1]{\textcolor{ALERT}{#1}} % loudest alert %% "\alert" is already a beamer pre-defined \newcommand*{\Scale}[2][4]{\scalebox{#1}{$#2$}}% \graphicspath{{images/}} % Put all images in this directory. Avoids clutter. % suppress frame numbering for backup slides % you always need the appendix for this! \newcommand{\backupbegin}{ \newcounter{framenumberappendix} \setcounter{framenumberappendix}{\value{framenumber}} } \newcommand{\backupend}{ \addtocounter{framenumberappendix}{-\value{framenumber}} \addtocounter{framenumber}{\value{framenumberappendix}} } \begin{document} \tikzstyle{every picture}+=[remember picture] { \setbeamertemplate{sidebar right}{\llap{\includegraphics[width=\paperwidth,height=\paperheight]{bubble2}}} \begin{frame}[c]%{\phantom{title page}} \begin{center} \begin{center} \begin{columns} \begin{column}{0.9\textwidth} \flushright%\fontspec{Trebuchet MS} \bfseries \Huge {Numerical Integration} \end{column} \begin{column}{0.2\textwidth} %\includegraphics[width=\textwidth]{SHiP-2} \end{column} \end{columns} \end{center} \quad \vspace{3em} \begin{columns} \begin{column}{0.6\textwidth} \flushright \vspace{-1.8em} {%\fontspec{Trebuchet MS} \large Marcin Chrzaszcz, Danny van Dyk\\\vspace{-0.1em}\small \href{mailto:mchrzasz@cern.ch}{mchrzasz@cern.ch}, \href{mailto:danny.van.dyk@gmail.com}{danny.van.dyk@gmail.com}} \end{column} \begin{column}{0.4\textwidth} \includegraphics[height=1.3cm]{uzh-transp} \end{column} \end{columns} \vspace{1em} \vspace{0.5em} \textcolor{normal text.fg!50!Comment}{Numerical Methods, \\ 26. September, 2016} \end{center} \end{frame} } \begin{frame}{Plan for today} \begin{itemize} \item \alert{General problem of estimating the integral of a continuous function $f(x)$ on a finite support}\\ \vfill \item \alert{Specific problems in which properties of the integrand can be used to our advantage}\\ What properties of $f(x)$ can we use make our live easier? \end{itemize} \end{frame} \begin{frame}{Setup} \end{frame} \begin{frame}{Constant approximation} \end{frame} \begin{frame}{Linear approximation} \end{frame} \begin{frame}{Wait a minute, I know this!} Integrate the interpolating polynomial! Newton-Coates! \begin{equation} \sum_k \omega_k = 1\,. \end{equation} \end{frame} \begin{frame}{Pathological example 1} \resizebox{.9\textwidth}{!}{ \begin{tikzpicture} \begin{axis}[% axis x line=center, axis y line=left, ymin=0.0,ymax=1.05, xmin=-1,xmax=+1, samples=160 ] \addplot[thick,black,domain=-1:0] { 1 / (1 + 25 * x * x) }; \addplot[thick,black,domain=0:+1] { 1 / (1 + 25 * x * x) }; \addplot[thick,red, domain=-1:0] { 1.0 - 16.8552 * x^2 + 123.36 * x^4 - 381.434 * x^6 + 494.91 * x^8 - 220.942 * x^(10) }; \addplot[thick,red, domain=0:+1] { 1.0 - 16.8552 * x^2 + 123.36 * x^4 - 381.434 * x^6 + 494.91 * x^8 - 220.942 * x^(10) }; \addplot[thick,red,only marks,mark=*,mark size=3pt] coordinates { (-1.0, 0.0384615) (-0.8, 0.0588235) (-0.6, 0.1) (-0.4, 0.2) (-0.2, 0.5) ( 0.0, 1.0) ( 0.2, 0.5) ( 0.4, 0.2) ( 0.6, 0.1) ( 0.8, 0.0588235) ( 1.0, 0.0384615) }; \end{axis} \end{tikzpicture} } \end{frame} \begin{frame}{Conclusion 1: We know how to fix it!} \only<1>{ When interpolating a function, we saw that using splines fixes the problem of oscillating interpolating polynomials.\\ \vfill We can now use this to stabilise our interpolation formula as well.\\ \vfill \begin{itemize} \item Let $M$ be the number of intervals in which we want to integrate. \item Let $N$ be the degree of the interpolating polynomial in each interval. \item Enforce that the interpolating function is continous, but not differentiable at the interval boundaries. \end{itemize} \vfill The integral can then be approximated as \begin{equation} I \approx \sum_{k=0}^{N \cdot M + 1} \omega_k f(x_k) \end{equation} with $x_k = a + (b - a) \frac{k}{N\cdot M}$\,. } \only<2->{ \resizebox{.9\textwidth}{!}{ \begin{tikzpicture} \begin{axis}[% axis x line=center, axis y line=left, ymin=0.0,ymax=1.05, xmin=-1,xmax=+1, samples=160 ] \addplot[thick,black,domain=-1:0] { 1 / (1 + 25 * x * x) }; \addplot[thick,black,domain=0:+1] { 1 / (1 + 25 * x * x) }; \only<3>{ \addplot+[smooth,red,name path=A1,domain=-1:-0.6,mark=none] { 0.348416 + 0.570136 * x + 0.260181 * x^2 }; \addplot+[draw=none,mark=none,name path=B1] {0}; \addplot+[gray] fill between[of=A1 and B1,soft clip={domain=-1:-0.6}]; } \only<4>{ \addplot+[smooth,red,name path=A2,domain=-0.6:-0.2,mark=none] { 1. + 3. * x + 2.5 * x^2 }; \addplot+[draw=none,mark=none,name path=B2] {0}; \addplot+[gray] fill between[of=A2 and B2,soft clip={domain=-0.6:-0.2}]; } \only<5>{ \addplot+[smooth,red,name path=A3,domain=-0.2:+0.2,mark=none] { 1. - 12.5 * x^2 }; \addplot+[draw=none,mark=none,name path=B3] {0}; \addplot+[gray] fill between[of=A3 and B3,soft clip={domain=-0.2:+0.2}]; } \only<6>{ \addplot+[smooth,red,name path=A4,domain=+0.2:+0.6,mark=none] { 1. - 3. * x + 2.5 * x^2 }; \addplot+[draw=none,mark=none,name path=B4] {0}; \addplot+[gray] fill between[of=A4 and B4,soft clip={domain=+0.2:0.6}]; } \only<7>{ \addplot+[smooth,red,name path=A5,domain=+0.6:+1,mark=none] { 0.348416 - 0.570136 * x + 0.260181 * x^2 }; \addplot+[draw=none,mark=none,name path=B5,domain=+0.6:+1] {0}; \addplot+[gray] fill between[of=A5 and B5,soft clip={domain=0.6:1}]; } \addplot[thick,red,only marks,mark=*,mark size=3pt] coordinates { (-1.0, 0.0384615) (-0.8, 0.0588235) (-0.6, 0.1) (-0.4, 0.2) (-0.2, 0.5) ( 0.0, 1.0) ( 0.2, 0.5) ( 0.4, 0.2) ( 0.6, 0.1) ( 0.8, 0.0588235) ( 1.0, 0.0384615) }; \end{axis} \end{tikzpicture} } } \end{frame} \begin{frame}{} \begin{equation} \omega_k = \begin{cases} \frac{1}{6} & k = 0 \lor k = N \cdot M + 1\\ \frac{4}{6} & k\,\text{even}\\ \frac{2}{6} & k\,\text{odd} \end{cases} \end{equation} \end{frame} \newcommand{\eps}{\varepsilon} \begin{frame}{Pathological example 2} \begin{equation*} I \equiv \int_{-3}^{+4} \mathrm{d}x\, \left[1 - \frac{\eps}{x^2 + \eps}\right] \, \quad \text{with }\eps = \frac{1}{9} \end{equation*} \begin{columns} \begin{column}{.5\textwidth} \resizebox{\textwidth}{!}{ \begin{tikzpicture} \begin{axis}[% axis x line=center, axis y line=left, ymin=0.0,ymax=1.05, xmin=-3,xmax=+4, samples=160 ] \addplot[thick,black,domain=-3:0] { 1 - 1/9 / (x^2 + 1/9) }; \addplot[thick,black,domain=0:+4] { 1 - 1/9 / (x^2 + 1/9) }; \addplot[thick,blue,only marks,mark=+,mark size=5pt] coordinates { ( 1, 0.54030 ) }; \end{axis} \end{tikzpicture} } \begin{equation*} \end{equation*} \end{column} \begin{column}{.5\textwidth} \begin{block}{Exact result} ~\\ \vspace{-2\bigskipamount} \begin{align*} I & = 5.57396 \end{align*} \end{block} \begin{block}{Entire range, 7 data points} ~\\ \vspace{-2\bigskipamount} \begin{align*} I_7 & = 6.25746 & \delta_7 & = 12.26\% \end{align*} \end{block} \begin{block}{Two integration, 5 data points} ~\\ \vspace{-2\bigskipamount} \begin{align*} I_5 & = 5.65645 & \delta_5 & = 1.47\% \end{align*} \end{block} \end{column} \end{columns} \end{frame} \backupbegin \begin{frame}\frametitle{Backup} \end{frame} \backupend \end{document}