0
$\begingroup$

I am trying to find out how to find a good interpolation of a periodic function I have from some data points.

The only problem is that I need to make sure that derivatives at the starting and ending points are fixed (not at every point), the function must be constrained between 0 and 1, and of course, smooth.

For a better explanation of my objective, here's a picture, where the red additions are mine to show how interpolation should behave:

target

data = {{0, 0}, {1.1, 0.8}, {1.4, 1}, {1.7, 0.8}, {2.6, 0.2}, {3.6, 
   0.06}, {5, 0}}

g[t_] := Interpolation[data, t]
Show[
 Plot[g[t], {t, 0, 5}],
 ListPlot[data]
 ]

All my attempts with Fit, Interpolation, and Bezier curves failed.

Any hints?

$\endgroup$
  • $\begingroup$ What is periodic about your function? $\endgroup$ – JimB Nov 13 '18 at 16:43
  • 1
    $\begingroup$ Unless you can get more data points, what about g[t_] := Interpolation[data, t, InterpolationOrder -> 2, Method -> "Spline"] ? $\endgroup$ – JimB Nov 13 '18 at 16:55
1
$\begingroup$
data = {{0, 0}, {1.1, 0.8}, {1.4, 1}, {1.7, 0.8}, {2.6, 0.2}, {3.6, 0.06}, {5, 0}};

Set the derivative to zero for first point, last point, and peak point.

data2 = ({{#[[1]]}, #[[2]]} & /@ 
    data) /. {{x_?(# == Min[data[[All, 1]]] || # == Max[data[[All, 1]]] || # ==
           data[[Position[data[[All, 2]], Max[data[[All, 2]]]][[1, 1]], 
            1]] &)}, v_} :> {{x}, v, 0}

(* {{{0}, 0, 0}, {{1.1}, 0.8}, {{1.4}, 1, 0}, {{1.7}, 0.8}, {{2.6}, 0.2}, 
   {{3.6}, 0.06}, {{5}, 0, 0}} *)

Interpolating the revised data

f = Interpolation[data2, InterpolationOrder -> 1];

Checking the derivatives

f' /@ {0, 1.4, 5}

(* {-1.11022*10^-16, 0., 0.} *)

Plotting

Plot[f[x], {x, 0, 5},
 Epilog -> {Red, AbsolutePointSize[6], Point[data]}]

enter image description here

Since the derivative is not known for all points, much of the plot is only piecewise continuous.

$\endgroup$
  • $\begingroup$ Wonderful! I just have one question that completes my doubts. Is it possible in Mathematica to interpolate as you did, but leaving some points unconstrained? For instance the fifth point, or third and sixth? Of course it would be a best fit and not what I was looking for, but it’s interesting nonetheless. $\endgroup$ – senseiwa Nov 14 '18 at 5:12
  • $\begingroup$ If f1 is the interpolated function and f2 is a fitted function, then f3[x_] = w*f1[x] + (1-w)*f2[x] with 0 < w < 1 would give you a weighted mixture. $\endgroup$ – Bob Hanlon Nov 14 '18 at 5:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.