# Fitting data without an equation

Let's say I have some data generated by anything. For practical sake, let's say I was able to generate a sequence of numbers through a recursion and I listed them out through a table of numbers.

F[1] = 1;
F[n_] := 3*F[n - 1]
H = Table[F[n], {n, 1, 10}]


Now I set the table of values to a variable 'w'

ListPlot[H]


Here I am plotting the data.

What I want to do now is to "fit" a curve that connects all those points. I just want to see the fitted curve on the plot together the data points. I don't even need (or want to) see the equation that best fits the data.

I tried using NonlinearModel and Fit, neither works well for me. The recursion is just an example. I could of course product new data from something else

• The simplest fit is linear interpolation between data points. And that is done by using the following magical incantation: ListPlot[H, Joined -> True]. Do you want anything fancier that this? If so, could you describe it in more detail?
– Jens
Mar 29, 2013 at 4:49
• add the option Joined->True and possibly PlotMarkers->Automatic to ListPlot
– acl
Mar 29, 2013 at 5:05
• Do you have information on what this plot is to be used for, i.e. what inferences are to be drawn from it Mar 29, 2013 at 7:14
• Nope, none at all. Mar 29, 2013 at 19:11

If you just want to see the plot:

ListPlot[H, Mesh -> Full, Joined -> True, PlotRange -> All, InterpolationOrder -> 2]


• What does the 'order' do? Mar 29, 2013 at 6:12
• @jak It smooths out the curve. Try with values from 0 to 3 Mar 29, 2013 at 6:16
• So I am guessing the higher the value, the better? Mar 29, 2013 at 6:21
• @jak why don't you position your cursor on that keyword and press F1? You'll get your answer right away... Mar 30, 2013 at 14:41
• It's interesting, when I make an recursion. If I set the InterpolationOrder greater than 2, my recurison starts back at $-1$ instead of 0 Apr 6, 2013 at 5:57

My best guess as to what you really want is Interpolation:

F[1] = 1;
F[n_] := 3*F[n - 1]
H = Table[F[n], {n, 1, 10}];

f = Interpolation[H]


InterpolatingFunction[{{1,10}},<>]

Plot[f[x], {x, 1, 10}]


• I am getting "InterpolatingFunction::dmval: Input value {0.000204286} lies outside the range of data in the interpolating function. Extrapolation will be used. >>" Mar 29, 2013 at 5:25
• @jak An InterpolatingFunction only matches the data its given and won't provide an accurate fit/prediction at values outside of the limits of the data. Here those limits are 1 and 10 as H is a list of 10 numbers (not x-y pairs) so Mma assigns an x-coord of 1,2,3... to each y value. When you try plot beyond the limits (as at $x\simeq0$ above) Mma warns that you're working outside of the 'safe' domain of f and that the results at these points may not be trustworthy. Often plots of an InterpolationFunction far from its 'safe' domain can look very strange compared to the data its based on Mar 29, 2013 at 10:36

You just need to plot the the power function:

Show[Plot[3^(n - 1), {n, 1, 10}], ListPlot[H]]


• My understanding was that the data aren't necessarily given by a known function...
– Jens
Mar 29, 2013 at 5:02
• @Jens, that's exactly what I mean. I just made up this example. Mar 29, 2013 at 5:28