Cubic Spline Interpolation (Natural)

Cubic spline interpolation with natural 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.07516004606833009*x^3+-0.3382202073074854*x^2+0.5427670899711728*x^1+0.12148094591798733*x^0};

			\addplot[][domain=-0.2:1]{+0.06901369090311398*x^3+-0.25171596512461897*x^2+0.560067938407746*x^1+0.12263433581375889*x^0};

			\addplot[][domain=1:5]{+0.0025014055495786265*x^3+-0.05217910906401291*x^2+0.36053108234714004*x^1+0.18914662116729425*x^0};

			\addplot[][domain=5:10]{+0.0034777888470503854*x^3+-0.0668248585260893*x^2+0.43375982965752197*x^1+0.06709870898332437*x^0};

			\addplot[][domain=10:15]{+-0.006725733907118523*x^3+0.23928082409897794*x^2+-2.6272969965931505*x^1+10.270621463152233*x^0};

			\addplot[][domain=15:20]{+0.004225146781423704*x^3+-0.25350880688542227*x^2+4.764547468172853*x^1+-26.688600860677784*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