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'


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

  • 4
    $\begingroup$ 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? $\endgroup$ – Jens Mar 29 '13 at 4:49
  • 1
    $\begingroup$ add the option Joined->True and possibly PlotMarkers->Automatic to ListPlot $\endgroup$ – acl Mar 29 '13 at 5:05
  • $\begingroup$ Do you have information on what this plot is to be used for, i.e. what inferences are to be drawn from it $\endgroup$ – image_doctor Mar 29 '13 at 7:14
  • $\begingroup$ Nope, none at all. $\endgroup$ – Hawk Mar 29 '13 at 19:11

If you just want to see the plot:

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

Mathematica graphics

  • $\begingroup$ What does the 'order' do? $\endgroup$ – Hawk Mar 29 '13 at 6:12
  • $\begingroup$ @jak It smooths out the curve. Try with values from 0 to 3 $\endgroup$ – Dr. belisarius Mar 29 '13 at 6:16
  • $\begingroup$ So I am guessing the higher the value, the better? $\endgroup$ – Hawk Mar 29 '13 at 6:21
  • $\begingroup$ @jak why don't you position your cursor on that keyword and press F1? You'll get your answer right away... $\endgroup$ – Sjoerd C. de Vries Mar 30 '13 at 14:41
  • $\begingroup$ 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 $\endgroup$ – Hawk Apr 6 '13 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]


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


  • $\begingroup$ I am getting "InterpolatingFunction::dmval: Input value {0.000204286} lies outside the range of data in the interpolating function. Extrapolation will be used. >>" $\endgroup$ – Hawk Mar 29 '13 at 5:25
  • $\begingroup$ @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 $\endgroup$ – fizzics Mar 29 '13 at 10:36

You just need to plot the the power function:

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


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

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.