Cubic Spline Interpolation (Not-a-Knot)

Cubic spline interpolation with not-a-knot boundary condition.

LaTeX source

\documentclass[11pt]{article}

% graphics
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\usepgfplotslibrary{fillbetween}


\begin{document}
	\begin{tikzpicture}

		\pgfplotsset{
			scale only axis,
		}

		\begin{axis}[
			xlabel=$x$,
			ylabel=$y$,
			samples=100,
			]\addplot [only marks] table {
-1.5 -1.2
-0.2 0
1 0.5
5 1
10 1.2
15 2
20 1
};
			
			\addplot[][domain=-1.5:-0.2]{+0.03919456795297435*x^3+-0.17512790499702052*x^2+0.5238455535837846*x^1+0.11208778346026153*x^0};

			\addplot[][domain=-0.2:1]{+0.03919456795297435*x^3+-0.17512790499702052*x^2+0.5238455535837846*x^1+0.11208778346026153*x^0};

			\addplot[][domain=1:5]{+0.004000209818982697*x^3+-0.06954483059504554*x^2+0.41826247918180964*x^1+0.1472821415942532*x^0};

			\addplot[][domain=5:10]{+0.002595140275858757*x^3+-0.048468787448186446*x^2+0.31288226344751413*x^1+0.3229158344847457*x^0};

			\addplot[][domain=10:15]{+-0.004359028055171752*x^3+0.16015626248272882*x^2+-1.7733682358616385*x^1+7.277084165515254*x^0};

			\addplot[][domain=15:20]{+-0.004359028055171752*x^3+0.16015626248272882*x^2+-1.7733682358616385*x^1+7.277084165515254*x^0};
		\end{axis}

	\end{tikzpicture}

\end{document}
(0 Posts)
Zürich-based Software Engineer with Google and Founder of Denk Development. Opinions are my own. I am interested in data science, software engineering, 3d-printing, arts, music, microcontrollers, and sports.
View all author’s posts