0

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?

senseiwa
  • 515
  • 2
  • 7

1 Answers1

2
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.

Bob Hanlon
  • 157,611
  • 7
  • 77
  • 198
  • 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. – senseiwa Nov 14 '18 at 05:12
  • 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. – Bob Hanlon Nov 14 '18 at 05:51
  • 1
    You might want to look at this solution https://mathematica.stackexchange.com/q/218764/1089 – chris Apr 04 '20 at 08:54