%% $Date: 2017-01-17 15:19:00#$
%% $Revision: 1 $
\index{interpolate\_linear}
\algdesc{Linear Interpolation}
{ %%%%%% Algorithm name %%%%%%
interpolate\_linear
}
{ %%%%%% Algorithm summary %%%%%%
This algorithm linearly interpolates a variable piecewise from one coordinate system to another. 
It is mostly used to fill gaps.
}
{%%%%%% Category %%%%%%%
Transforms
}  
{ %%%%%% Inputs %%%%%%
$x$ & Vector & x-coordinates of the data points (must be increasing). \\
$f$ & Vector & Data points to interpolate. \\
$x_{interp}$ & Vector & New set of x-coordinates to use in interpolation. \\
$f_{left}$ & Coeff, optional & Value to return when $x_{interp} < x_0$. Default is $f_0$.\\
$f_{right}$ & Coeff, optional & Value to return when $x_{interp} > x_n$. Default is $f_n$.
}
{ %%%%%% Outputs %%%%%%
$f_{interp}$ & Vector & Interpolated values of $f$.
}
{ %%%%%% Formula %%%%%%
For each value of $x_{interp}$ the two surrounding points are found and designated $x_a$ and $x_b$, with 
corresponding values $f_a$ and $f_b$. Then $f_{interp}$ is calculated piecewise as follows:

\begin{displaymath}
 f_{interp}[i] = f_a + (x_{interp}[i] - x_a) \frac{f_b - f_a}{x_b - x_a}
\end{displaymath}

Values where $x_{interp}$ is less than $x_0$ are replaced with $f_{left}$, if provided, or $f_0$.
Likewise, $f_{right}$ if given, or $f_n$ are substituted where $x_{interp}$ is greater than $x_n$. \\
\\
\underline{Important:} in the current version of the algorithm, the corresponding  $i^{th}$ value is interpolated only if:

\begin{itemize}
  \item $x_{interp}[i]$ doesn't exist in $x$
  \item $f(x) = NaN$ if $x_{interp}[i]$ exists in $x$
\end{itemize}

}
{ %%%%%% Author %%%%%%

}
{ %%%%%% References %%%%%% 

}


