\documentclass[11 pt,xcolor={dvipsnames,svgnames,x11names,table}]{beamer}

\usepackage[english]{babel} 
\usepackage{polski}         


\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}

%\logo{\kern+1.em\includegraphics[height=1cm]{SHiP-3_LightCharcoal}}
                            

\usepackage[lf]{berenis}
\usepackage[LY1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{cases}
\usepackage{mathtools}
\usepackage{emerald}
\usefonttheme{professionalfonts}
\usepackage[no-math]{fontspec}		
\defaultfontfeatures{Mapping=tex-text}	% This seems to be important for mapping glyphs properly

\setmainfont{Gillius ADF}			% Beamer ignores "main font" in favor of sans font
\setsansfont{Gillius ADF}			% This is the font that beamer will use by default
% \setmainfont{Gill Sans Light}		% Prettier, but harder to read

\setbeamerfont{title}{family=\fontspec{Gillius ADF}}

\input t1augie.fd

%\newcommand{\handwriting}{\fontspec{augie}} % From Emerald City, free font
%\newcommand{\handwriting}{\usefont{T1}{fau}{m}{n}} % From Emerald City, free font
% \newcommand{\handwriting}{}	% If you prefer no special handwriting font or don't have augie

%% Gill Sans doesn't look very nice when boldfaced
%% This is a hack to use Helvetica instead
%% Usage: \textbf{\forbold some stuff}
%\newcommand{\forbold}{\fontspec{Arial}}

\usepackage{graphicx}
\usepackage[export]{adjustbox}

\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{bm}
\usepackage{colortbl}
\usepackage{mathrsfs} 			% For Weinberg-esque letters
\usepackage{cancel}				% For "SUSY-breaking" symbol
\usepackage{slashed}            % for slashed characters in math mode
\usepackage{bbm}                % for \mathbbm{1} (unit matrix)
\usepackage{amsthm}				% For theorem environment
\usepackage{multirow}			% For multi row cells in table
\usepackage{arydshln} 			% For dashed lines in arrays and tables
\usepackage{siunitx}
\usepackage{xhfill}
\usepackage{grffile}
\usepackage{textpos}
\usepackage{subfigure}
\usepackage{tikz}
\usepackage{hyperref}
%\usepackage{hepparticles}    
\usepackage[italic]{hepparticles}     

\usepackage{hepnicenames} 

% Drawing a line
\tikzstyle{lw} = [line width=20pt]
\newcommand{\topline}{%
  \tikz[remember picture,overlay] {%
    \draw[crimsonred] ([yshift=-23.5pt]current page.north west)
             -- ([yshift=-23.5pt,xshift=\paperwidth]current page.north west);}}



% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
\usepackage{tikzfeynman}		% For Feynman diagrams
\usetikzlibrary{arrows,shapes}
\usetikzlibrary{trees}
\usetikzlibrary{matrix,arrows} 				% For commutative diagram
% http://www.felixl.de/commu.pdf
\usetikzlibrary{positioning}				% For "above of=" commands
\usetikzlibrary{calc,through}				% For coordinates
\usetikzlibrary{decorations.pathreplacing}  % For curly braces
% http://www.math.ucla.edu/~getreuer/tikz.html
\usepackage{pgffor}							% For repeating patterns

\usetikzlibrary{decorations.pathmorphing}	% For Feynman Diagrams
\usetikzlibrary{decorations.markings}
\tikzset{
	% >=stealth', %%  Uncomment for more conventional arrows
	vector/.style={decorate, decoration={snake}, draw},
	provector/.style={decorate, decoration={snake,amplitude=2.5pt}, draw},
	antivector/.style={decorate, decoration={snake,amplitude=-2.5pt}, draw},
	fermion/.style={draw=gray, postaction={decorate},
		decoration={markings,mark=at position .55 with {\arrow[draw=gray]{>}}}},
	fermionbar/.style={draw=gray, postaction={decorate},
		decoration={markings,mark=at position .55 with {\arrow[draw=gray]{<}}}},
	fermionnoarrow/.style={draw=gray},
	gluon/.style={decorate, draw=black,
		decoration={coil,amplitude=4pt, segment length=5pt}},
	scalar/.style={dashed,draw=black, postaction={decorate},
		decoration={markings,mark=at position .55 with {\arrow[draw=black]{>}}}},
	scalarbar/.style={dashed,draw=black, postaction={decorate},
		decoration={markings,mark=at position .55 with {\arrow[draw=black]{<}}}},
	scalarnoarrow/.style={dashed,draw=black},
	electron/.style={draw=black, postaction={decorate},
		decoration={markings,mark=at position .55 with {\arrow[draw=black]{>}}}},
	bigvector/.style={decorate, decoration={snake,amplitude=4pt}, draw},
}

% TIKZ - for block diagrams, 
% from http://www.texample.net/tikz/examples/control-system-principles/
% \usetikzlibrary{shapes,arrows}
\tikzstyle{block} = [draw, rectangle, 
minimum height=3em, minimum width=6em]




\usetikzlibrary{backgrounds}
\usetikzlibrary{mindmap,trees}	% For mind map
\newcommand{\degree}{\ensuremath{^\circ}}
\newcommand{\E}{\mathrm{E}}
\newcommand{\Var}{\mathrm{Var}}
\newcommand{\Cov}{\mathrm{Cov}}
\newcommand\Ts{\rule{0pt}{2.6ex}}       % Top strut
\newcommand\Bs{\rule[-1.2ex]{0pt}{0pt}} % Bottom strut

\graphicspath{{images/}}	% Put all images in this directory. Avoids clutter.

% 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$}}%

\def\Put(#1,#2)#3{\leavevmode\makebox(0,0){\put(#1,#2){#3}}}

\usepackage{gmp}
\usepackage[final]{feynmp-auto}

\usepackage[backend=bibtex,style=numeric-comp,firstinits=true]{biblatex}
\bibliography{bib}
\setbeamertemplate{bibliography item}[text]

\makeatletter\let\frametextheight\beamer@frametextheight\makeatother

% 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}} 
}


\definecolor{links}{HTML}{2A1B81}
%\hypersetup{colorlinks,linkcolor=,urlcolor=links}

% For shapo's formulas:
\def\lsi{\raise0.3ex\hbox{$<$\kern-0.75em\raise-1.1ex\hbox{$\sim$}}}
\def\gsi{\raise0.3ex\hbox{$>$\kern-0.75em\raise-1.1ex\hbox{$\sim$}}}
\newcommand{\lsim}{\mathop{\lsi}}
\newcommand{\gsim}{\mathop{\gsi}}
\newcommand{\wt}{\widetilde}
%\newcommand{\ol}{\overline}
\newcommand{\Tr}{\rm{Tr}}
\newcommand{\tr}{\rm{tr}}
\newcommand{\eqn}[1]{&\hspace{-0.7em}#1\hspace{-0.7em}&}
\newcommand{\vev}[1]{\rm{$\langle #1 \rangle$}}
\newcommand{\abs}[1]{\rm{$\left| #1 \right|$}}
\newcommand{\eV}{\rm{eV}}
\newcommand{\keV}{\rm{keV}}
\newcommand{\GeV}{\rm{GeV}}
\newcommand{\im}{\rm{Im}}
\newcommand{\disp}{\displaystyle}
\def\be{\begin{equation}}
\def\ee{\end{equation}}
\def\ba{\begin{eqnarray}}
\def\ea{\end{eqnarray}}
\def\d{\partial}
\def\l{\left(}
\def\r{\right)}
\def\la{\langle}
\def\ra{\rangle}
\def\e{{\rm e}}
\def\Br{{\rm Br}}
\def\fixme{{\color{red} FIXME!}}
\def\mc{{\color{Magenta}{MC}}\xspace}
\def\pdf{{\rm p.d.f.}}
\def\ARROW{{\color{JungleGreen}{$\Rrightarrow$}}\xspace}
\def\ARROWR{{\color{WildStrawberry}{$\Rrightarrow$}}\xspace} 

\author{ {\fontspec{Trebuchet MS}Marcin Chrz\k{a}szcz, Danny van Dyk} (UZH)}
\institute{UZH}
\title[Function interpolation]{Function Interpolation}
\date{21 September 2016}


\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 {Function Interpolation}
		\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 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}}

\end{column}
\begin{column}{0.4\textwidth}
\includegraphics[height=1.3cm]{uzh-transp}
\end{column}
\end{columns}

\vspace{1em}
%		\footnotesize\textcolor{gray}{With N. Serra, B. Storaci\\Thanks to the theory support from M. Shaposhnikov, D. Gorbunov}\normalsize\\
\vspace{0.5em}
	\textcolor{normal text.fg!50!Comment}{Numerical Methods, \\ 21 September, 2016}
\end{center}
\end{frame}
}



\begin{frame}\frametitle{Interpolation - graphical interpretation}
\begin{small}


\ARROW Let's assume we have a given function in a tabular form:
\begin{tabular}{c||c|c|c|c|c}
$x_i$ & $x_1$ & $x_2$ & $x_3$ & ... & $x_n$ \\ \hline
$f_i=f(x_i)$ & $f_1$ & $f_2$ & $f_3$ & ... & $f_n$ \\
\end{tabular}\\
\ARROWR The $x_i$ are data points.\\
\ARROW The problem is how to calculate the function values between the points ({\it interpolation}) or outside ({\it extrapolation} - see next lecture!) .
\end{small}
\begin{center}
\includegraphics[angle=-90,width=0.5\textwidth]{images/mass_resolution_Bconstr_afterSel_errBand_scaled.pdf}
\end{center}
\end{frame}



\begin{frame}\frametitle{Interpolation - formal formulation}
\begin{small}

\ARROW On the interval: $\left[ a, b \right] \subset \mathbb{R}$ and set of points: $D=(x_i, y_i)$, $x_i \neq x_j~ \Leftrightarrow~ i \neq j$.\\
\ARROW The interpolation is to find a function $F:\left[ a, b \right] \rightarrow  \mathbb{R}$ that satisfies:
\begin{align*}
\forall (x_i,y_i) \in D:~~~ F(x_i)=y_i
\end{align*}
\ARROW The above equation is called the interpolation equation.\\
\ARROW The interpolation error:
\begin{align*}
\epsilon(x)=f(x)-F(x),
\end{align*}
where $f(x)$ is the function that is being interpolated.\\
\ARROW Each interpolation method has different errors, each of it can be estimated.
\end{small}

\end{frame}



\begin{frame}\frametitle{Linear Interpolation}
\begin{small}

\ARROW Let's say we have $n+1$ interpolation points: $(y_i, x_i)$.\\
\ARROW The linear interpolation is given with with the equation:
\begin{align*}
F(x)=\sum_{j=0}^n a_j \psi_j(x)=a_0 \psi_0(x) + a_1 \psi_1(x) + a_2 \psi_2(x)+ ... + a_n \psi_n(x),
\end{align*}
where:
\begin{itemize}
\item $a_j$ - parameter,
\item $\psi_j(x)$ - base function.
\end{itemize}
\ARROW Now the only thing one needs to do is to find the $a_i$ coefficients. Now there are infinite number such solutions so we need to assume that the number interpolation points is equal to number of base functions. 


\end{small}

\end{frame}


\begin{frame}\frametitle{Linear Interpolation}
\begin{small}

\ARROW Now to find all the $a_i$ one just needs to solve the linear equation system:
\begin{align*}
\begin{pmatrix}
\psi_0(x_0) & \psi_1(x_0) & ... & \psi_n(x_0) \\
\psi_0(x_1) & \psi_1(x_1) & ... & \psi_n(x_1) \\
& ... \\
\psi_0(x_0) & \psi_1(x_0) & ... & \psi_n(x_2) 
\end{pmatrix}
\begin{pmatrix}
a_0\\
a_1\\
...\\
a_n
\end{pmatrix}=
\begin{pmatrix}
y_0\\
y_1\\
...\\
y_n
\end{pmatrix}
\end{align*}
\ARROW The only necessary condition to solve the equation is that the:
\begin{align*}
\det \left[ \psi_i(x_j) \right] \neq 0
\end{align*}
\ARROW The polynomial of the order $n$ has $n+1$ base functions, so system has only one solution.\\
\ARROW We can choose the base functions on many different ways. This depends on the input points and our own judgement. Often use are trigonometric functions and polynomials.\\
\ARROW The proper selection of the base function can hugely simplify the problem by making the matrix triangular or even diagonal.

\end{small}

\end{frame}

\begin{frame}\frametitle{Linear Interpolation, simplest base}
\begin{small}
\begin{exampleblock}{Theorem:}
If all of the interpolation points $x_0,x_1,...,x_n$ are pair different there exists one and only one solution of the interpolation function of the order max. $n$. 
\end{exampleblock}

The simplest base functions one can imagine to use is the natural base:
\begin{align*}
\psi_0=1,~~~\psi_1=x,~~~\psi_2=x^2,~~~...~~~, \psi_n=x^n
\end{align*}
\begin{alertblock}{Attention/Achtung:}
This kind of interpolation is wrongly conditioned: small changes of input parameters will cause large output differences.
\end{alertblock}

\ARROW Because of the above it is used almost not used in practice. \\
\ARROW For education purposes we will analyse it. 
\end{small}

\end{frame}

\begin{frame}\frametitle{Linear Interpolation, simplest base}
\begin{small}
\ARROW When using natural base the interpolation polynomial will have the structure:
\begin{align*}
F(x)=a_0+a_1 x + a_2 x^2 + a_3 x^3 ... a_n x^n
\end{align*}
\ARROW Now base matrix (so-called Vandermonde matrix) has the form:
\begin{align*}
V=\begin{pmatrix}
1 & x_0 & x_0^2 & ... & x_0^n  \\
1 & x_1 & x_1^2 & ... & x_1^n  \\
& ... \\
1 & x_n & x_n^2 & ... & x_n^n  \\
\end{pmatrix}
\end{align*}
\ARROW Now the only thing one needs to do is to solve:
\begin{align*}
\begin{pmatrix}
1 & x_0 & x_0^2 & ... & x_0^n  \\
1 & x_1 & x_1^2 & ... & x_1^n  \\
& ... \\
1 & x_n & x_n^2 & ... & x_n^n  \\
\end{pmatrix}
\begin{pmatrix}
a_0\\
a_1\\
...\\
a_n
\end{pmatrix}=
\begin{pmatrix}
y_0\\
y_1\\
...\\
y_n
\end{pmatrix}
\end{align*}
\ARROW Because the natural base is wrongly conditioned the increase of the interpolation points significantly increases the condition parameter.

\end{small}

\end{frame}


\begin{frame}\frametitle{Lagrange interpolation}
\begin{small}
\ARROW Now let's choose a better base function that are given by:
\begin{align}
\label{eq:langrange}
l_i(x)= \prod_{j=0,~j \neq i}^n \frac{x-x_j}{x_i-x_j} = \frac{(x-x_0)(x-x_1)...(x-x_n)}{(x_i-x_0)(x_i-x_1)...(x_i-x_n)}
\end{align}
\ARROW It is easy to notice:
\begin{align*}
l_i(x_j)=\begin{cases}
0~~~i \neq j \\
1~~~i=j
\end{cases}
\end{align*}
\ARROW Now putting this into base matrix we get:
\begin{align*}
\begin{pmatrix}
1 & 0 &  0 & ... & 0  \\
0 & 1 & 0 & ... & 0  \\
& ... \\
0 & 0 & 0 & ... & 1  \\
\end{pmatrix}
\begin{pmatrix}
a_0\\
a_1\\
...\\
a_n
\end{pmatrix}=
\begin{pmatrix}
y_0\\
y_1\\
...\\
y_n
\end{pmatrix}
\end{align*}
\ARROW Now this is something we like :) The interpolating function then takes the form:
\begin{align*}
F(x)=L_n(x)=\sum_{i=0}^n y_i l_i(x)
\end{align*}

\end{small}
\end{frame}



\begin{frame}\frametitle{Lagrange interpolation - the algorithm}
\begin{small}
\begin{enumerate}
\item Get the input data $(x_i,y_i),~i=0,...,n$. 
\item The coefficients of the polynomial are $y_i$. 
\item Calculate the base functions from Eq.~\ref{eq:langrange}.
\item Put everything together to get the $L_n$ Lagrange polynomial.
\end{enumerate}
\begin{alertblock}{Disadvantage:}
The problem with this method is the fact that if you add another interpolation point you need to start over and recalculate everything.
\end{alertblock}

\begin{exampleblock}{Advantege}
\only<1>{
It is very popular and simple method. It is used in many different places: differential equations, numerical integrations, etc.  Because of this the precision of the method depends on the precision of the interpolation is self:
\begin{align*}
\epsilon(x) =  f(x) - F(x) = \frac{f^{(n+1}(\xi) }{(n+1)!} \omega_n(x)
\end{align*}
}
\only<2>{
where:\\
$\omega_n(x)=(x-x_0)(x-x_1)...(x-x_n)$\\
$f$ function of class $C^{n+1}$ on $\left [a,b\right]$\\
$\xi$ average values.h
}
\end{exampleblock}


\end{small}
\end{frame}



\begin{frame}\frametitle{Newton interpolation}
\begin{small}
\ARROW Sir Isaac Newton proposed a different base for the problem:
\begin{align*}
p_0(x) & =1\\
p_1(x) & =(x-x_0)\\
p_2(x) & =(x-x_0)(x-x_1)\\
...\\
p_n(x) & =(x-x_0)(x-x_1)...(x-x_n)
\end{align*}
\only<1>{
\ARROW Using the above functions the basis matrix takes a nice form:
\begin{align*}
V=\begin{pmatrix}
1 & 0 & 0 & ... & 0  \\
1 & p_1(x_1) &  0 & ... & 0  \\
& ... \\
1 & p_1(x_n) & p_2(x_n) & ... & p_n(x_n)  \\
\end{pmatrix}
\end{align*}
}
\only<2>{
\ARROW And the linear equation system:
\begin{align*}
\begin{pmatrix}
1 & 0 & 0 & ... & 0  \\
1 & p_1(x_1) &  0 & ... & 0  \\
& ... \\
1 & p_1(x_n) & p_2(x_n) & ... & p_n(x_n)  \\
\end{pmatrix}
\begin{pmatrix}
a_0\\
a_1\\
...\\
a_n
\end{pmatrix}
=
\begin{pmatrix}
y_0\\
y_1\\
...\\
y_n
\end{pmatrix}
\end{align*}


}
\end{small}
\end{frame}



\begin{frame}\frametitle{Newton interpolation}
\begin{small}
\ARROW We can solve the aforementioned system by noticing that $a_0$ depends only on $y_0$, $a_1$ depends on $y_0$ and $y_1$, etc.\\
\ARROW They can be calculated using difference quotient:
\begin{align*}
f\left[ x_0,x_1 \right] =\frac{y_1-y_0}{x_1-x_0},~~f\left[ x_1,x_2 \right] =\frac{y_2-y_1}{x_2-x_1}, \rm~etc.
\end{align*}
\begin{align*}
f\left[ x_0,x_1, x_2 \right] = \frac{ f\left[ x_1,x_2 \right]- f\left[x_0,x_1 \right]  }{x_2-x_1}
\end{align*}
\ARROW In general:
\begin{align*}
f\left[ x_i,x_{i+1},..., x_{i+k} \right] = \frac{ f\left[ x_{i+1},x_{i+2},...,x_{i+k} \right] - f\left[ x_{i},x_{i+1},...,x_{i+k-1} \right]}{x_{i+k}-x_i}
\end{align*}
\ARROW Using difference quotient we can calculate the coefficients:
\begin{align*}
a_i=f\left[x_0,x_1,...,x_i\right]
\end{align*}
\end{small}
\end{frame}



\begin{frame}\frametitle{Newton interpolation, the algorithm}
\begin{small}

\begin{itemize}
\item We read the input interpolating points: $(x_i,y_i)$, $i=0,1,....,n$.
\item Calculate the polynomial coefficients in an iterative way.
\item Calculate the base functions.
\item Put things together to get the Newton interpolation polynomial.
\end{itemize}

\begin{exampleblock}{Why do we bother?}
\ARROWR Despite the procedure seems more complicated then the Lagrange interpolation it has a huge advantage: adding one more interpolation point does require to repeat the whole procedure, but we can reuse the previous steps.
\end{exampleblock}

\end{small}
\end{frame}



\begin{frame}\frametitle{First degree spline function}
\begin{small}

\ARROW Till now using couple numerical methods we were able to calculate coefficients of a big single polynomial equation.\\
\ARROW Now we are smarter then Newton and Lagrange were over 300 years ago!\\
\ARROW We can use several interpolating functions and then glue them (splice) them together!\\
\ARROW In order to do so we divide the domain of the $F$ function $\left[ a,b \right]$ into:
\begin{align*}
a=x_0<x_1<x_2<...<x_n=b
\end{align*}
\ARROW The simplest is to use linear functions:
\begin{align*}
s(x)=\begin{cases}
s_0(x)~~~~x \in \left[x_0,x_1 \right)\\
s_1(x)~~~~x \in \left[x_1,x_2 \right)\\
...\\
s_{n-1}(x)~~~~x \in \left[x_{n-1},x_n \right),
\end{cases}
\end{align*}
where
\begin{align*}
s_k(x)=a_{k,0}+a_{k,1}(x-x_k)~~x \in \left[ x_k,  x_{k+1} \right)
\end{align*}

\end{small}
\end{frame}


\begin{frame}\frametitle{First degree spline function}
\begin{small}

\ARROW The above defined functions $s_k(x)$ need to obey the conditions:
\begin{align*}
s_k(x_k ) & = y_k\\
s_k(x_{k+1}) &  = s_{k+1}(x_{k+1})
\end{align*}
\ARROW From the above we can calculate the linear equation coefficients:
\begin{align*}
a_{k,0} & =y_k\\
a_{k,1} & =\frac{y_{k+1} - y_k}{x_{k+1}-x_k}
\end{align*}

\begin{exampleblock}{Advantage:}
\ARROWR The biggest advantage of this method is it's simplicity. If you have a large number of interpolating points that are ''densely '' packed you can get very good and fast aproximation with this function.
\end{exampleblock}

\begin{alertblock}{Disadvantage:}
\ARROW The interpolating function is not smooth on the interpolation points.
\end{alertblock}

\end{small}
\end{frame}

\begin{frame}\frametitle{Third degree spline function}
\begin{small}
\ARROW As mentioned before the first degree spline function suffer from the continuity problem. \\
\ARROW A solution would be to use the higher order polynomials to aproximate the function. For example the 3rd order:
\begin{align*}
s_k(x)=a_{k,0} + a_{k,1}(x-x_k)+  a_{k,2}(x-x_k)^2 +  a_{k,3}(x-x_k)^3,~~~~x \in \left[x_k,x_{k+1} \right)
\end{align*}
\ARROW Now this polynomial needs to obey conditions:
\begin{align*}
s_k(x_k)&=y_k\\
s_k(x_{k+1})& = s_{k+1}(x_{k+1})\\
s^{\prime}_k(x_{k+1})& = s^{\prime}_{k+1}(x_{k+1})\\
s^{\prime\prime}_k(x_{k+1})& = s^{\prime\prime}_{k+1}(x_{k+1})
\end{align*}
\ARROW In total we will have $4n$ coefficients to find. But we will only have $4n-2$ equations.\\
\ARROW To solve the system we need to assume somethings about the endpoints (there are many options here).\\
\ARROW The most popular ones are:
\begin{align*}
&s^{\prime}(a)=f^{\prime}(a)~~~~s^{\prime}(b)=f^{\prime}(b)~~~~ {\rm or}\\
&s^{\prime\prime}(a)=s^{\prime\prime}(b)=0
\end{align*}


\end{small}
\end{frame}


\begin{frame}\frametitle{Third degree spline function}
\begin{small}
\ARROW Now to efficiently solve the system we will define temporary variables:
\begin{align*}
h_k&=x_{k+1}-x_k\\
d_k&=\frac{y_{k+1}-y_k}{h_k}\\
m_k&=s^{\prime\prime}(x_k)
\end{align*}
\ARROW Now the second derivative can be interpolated using the Lagrange polynomial:
\begin{align*}
s_k^{\prime\prime}(x)=s^{\prime\prime}(x)\frac{x-x_{k+1}}{x_{k}-x_{k+1}}+s^{\prime\prime}(x)\frac{x-x_{k}}{x_{k+1}-x_{k}}=\frac{m_k}{h_k}(x_{k+1}-x) + \frac{m_{k+}}{h_k}(x-x_k)
\end{align*}
\ARROW Now if we integrate the above equation (two times):
\begin{align*}
s_k^{\prime}(x)=-\frac{m_k}{2h_k}(x_{k+1}-x)^2 + \frac{m_{k+}}{2h_k}(x-x_k)^2 -p_k + q_k\\
s_k(x)=\frac{m_k}{6h_k}(x_{k+1}-x)^3 + \frac{m_{k+1}}{3h_k}(x-x_k)^3+p_k(x_{k+1}-x)+q_k(x-x_k)
\end{align*}

\end{small}
\end{frame}



\begin{frame}\frametitle{Third degree spline function}
\begin{small}
\ARROW Now we need to calculate the $s_k(x)$ for $x_k$ and $x_{k+1}$ using relations: $s_k(x_k)=y_k$ and $s_k(x_k+1)=y_{k+1}$:
\begin{align*}
x_k(x_k) & =y_k  = \frac{m_k}{6h_k}(x_{k+1}-x_k)^3 + p_k(x_{k+1}-x_k)\\
x_k(x_{k+1}) & =y_{k+1}  = \frac{m_{k+1}}{3h_k}(x_{k+1}-x_k)^3 + q_k (x_{k+1} -x_k)
\end{align*}
\ARROW From which we get:
\begin{align*}
p_k&=\frac{y_k}{h_k}-\frac{m_k h_k}{6}\\
p_{k+1}&=\frac{y_{k+1}}{h_{k+1}}-\frac{m_{k+1} h_{k+1}}{6}
\end{align*}
\ARROW Putting all the things together:
\begin{align}
S_k(x)= &\frac{m_k}{6h_k} (x_k-x)^3 + \frac{m_{k+1}}{6h_k}(x-x_k)^3+ \left( \frac{y_k}{h_k}  -\frac{m_k h_k}{6}\right) (x_{k+1}-x)\\ + & \left(\frac{y_{k+1}}{h_k} - \frac{m_{k+1} h_k}{6} \right) (x-x_k)
\label{eq:almostthere}
\end{align}
\end{small}
\end{frame}


\begin{frame}\frametitle{Third degree spline function}
\begin{small}
\ARROW The only unknown in the above equation are the $m_i$ variables. To get those we need to use the equation: $S^{\prime}_{k-1}(x_k)=s^{\prime}(x_k)$:
\begin{align*}
-\frac{1}{3}m_k h_k - \frac{1}{6} m_{k+1}h_k + d_k = \frac{1}{3}m_k h_{k-1} + \frac{1}{6}m_{k-1}h_{k-1}+d_{k-1} 
\end{align*}
\ARROW So the complete solution is:
\begin{align*}
a_{k,0}&=y_k\\
a_{k,1}&=d_k -\frac{h_k}{6}(2m_k+m_{k+1})\\
a_{k,2}&= \frac{m_k}{2}\\
a_{k,3}&= \frac{m_{k+1}-m_k}{6 h_k}
\end{align*}
\ARROW To get the $m_0$ and $m_n$ one needs to use one of the aforementioned conditions.

\end{small}
\end{frame}


\begin{frame}\frametitle{Third degree spline function algorithm}
\begin{small}

\begin{itemize}
\item Get the input interpolation points.
\item Calculate the temporary variables: $d_i, h_i$.
\item Assume adequate conditions to get $m_0$, $m_n$.
\item Solve linear equation system.
\item Obtained values of the $a_{i,j}$ coefficients put in the interpolation equation.
\end{itemize}


\end{small}
\end{frame}



\begin{frame}\frametitle{Summary}
\begin{small}

\ARROW Interpolation playes essential role in almost all numerical methods!\\
\ARROW Even very old algorithms like Lagrange are still used(we used it in splines).\\
\ARROW There is a lot of algorithms on the market. From simple Lagrange and Newton interpolation algorithms up to modern splines.\\
\ARROW The most common used today are spline. They require a bit of work but they work very effectively.\\
 


\end{small}
\end{frame}


\backupbegin   

\begin{frame}\frametitle{Backup}


\end{frame}










\backupend			
\end{document}
