Cubic Spline Interpolation Periodic with Concatenated Splines
Cubic spline interpolation on a set of points. The first spline was attached to the right end of the interpolation result and the last spline to the beginning. The boundary condition is called periodic.
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[color=gray][domain=-6.5:-1.5]{+0.03576951482985687*(x+21.5)^3+-1.773213533661014*(x+21.5)^2+28.77567246051788*(x+21.5)^1+-151.38415438480703*(x+21.5)^0-2.2}; \addplot[][domain=-1.5:-0.2]{+-0.19663701171489076*x^3+-0.5119091965866099*x^2+0.5621211492212532*x^1+0.13132750161399592*x^0}; \addplot[][domain=-0.2:1]{+0.10145185255956035*x^3+-0.33305587802193926*x^2+0.5978918129341874*x^1+0.13371221252819154*x^0}; \addplot[][domain=1:5]{+0.0002291041752526848*x^3+-0.02938763286901627*x^2+0.2942235677812644*x^1+0.23493496091249919*x^0}; \addplot[][domain=5:10]{+0.006089011958643077*x^3+-0.11728624961987216*x^2+0.7337166515355439*x^1+-0.4975535120112999*x^0}; \addplot[][domain=10:15]{+-0.015264631697124989*x^3+0.5233230600531698*x^2+-5.6723764451948755*x^1+20.856090143756767*x^0}; \addplot[][domain=15:20]{+0.03576951482985687*x^3+-1.773213533661014*x^2+28.77567246051788*x^1+-151.38415438480703*x^0}; \addplot[color=gray][domain=20:21.3]{+-0.19663701171489076*(x-21.5)^3+-0.5119091965866099*(x-21.5)^2+0.5621211492212532*(x-21.5)^1+0.13132750161399592*(x-21.5)^0+2.2}; \end{axis} \end{tikzpicture} \end{document}