# Extend a function defined for integers to a differentiable function of a real variable

Here is a function that calculates the probability of randomly landing on a Fibonacci number not greater than $n$:

f[n_Integer] := (Floor[Log[GoldenRatio, Sqrt[5] (n + (1/2))]] - 1)/n


How can I extend/complete it to some differentiable function that agrees with the original values when given an "integer" input?

• Have a look at Interpolation. Jan 8 '14 at 9:39

as b.gatessucks said, you can use Interpolation:

f[n_Integer] := (Floor[Log[GoldenRatio, Sqrt[5] (n + (1/2))]] - 1)/n
data = Table[{n, f[n]}, {n, 50}];
g = Interpolation[data];
p1 = Plot[g[x], {x, 1, 70}, AxesOrigin -> {0, 0}];
p2 = ListPlot[data, Mesh -> True, Filling -> Axis,
PlotStyle -> {Red, PointSize[0.015]}];

Show[p1, p2, Frame -> True]


There are many other functions in M for this sort of thing as described here http://reference.wolfram.com/mathematica/tutorial/ApproximateFunctionsAndInterpolation.html

Now you can take the derivative of g[x] and also integrate it etc.. as any other function:

  D[g[x], x]


  Integrate[g[x], {x, 1, 50}] // N
(* 17.4376 *)