1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Fitting a curve in log-linear plot.

  1. Nov 19, 2011 #1
    Hi all,

    I want to fit a curve through 6 points (please see figure attached, the curve in the picture is a drawn one not a fitted one. That is just to give a feel how the fitted curve would look like.) in a log-linear plot. Is there any way I can do it? Thanks.

    Attached Files:

  2. jcsd
  3. Nov 19, 2011 #2

    Simon Bridge

    User Avatar
    Science Advisor
    Homework Helper

    What sort of curve are you expecting?

    The data in your example are so scattered it could almost probably a straight line! You would not normally assume the points represent the wigglyness of the curve in the way you just did.
  4. Nov 19, 2011 #3

    Stephen Tashi

    User Avatar
    Science Advisor

    When you want a curve to go exactly through a number of points, this is called "interpolating" a curve rather than "fitting" a curve. An interesting thing about your problem is that, in the curve you drew, y is not a function of x. This suggests trying a parametric representation where x = f(t) and y = g(t).

    I can't tell whether your goal is to find a "nice" formula for the curve that only involves a few multiplications and divisions or whether you would be satisfied with a curve that had several different sections, each with a different formula for it. An example of defining an interpolation curve in pieces is "spline" interpolation.

    For a "one piece fit", you could try setting
    [itex] f(t) = a_0 + a_1 t + a_2 t^2 + ...+a_5 t^5 [/itex]
    [itex] g(t) = b_0 + b_1 t + b_2 t^2 + ...+b_5 t^5 [/itex]

    where [itex] a_i, b_i [/itex] are unknown constants. Substituting the data points [itex] (x_k,y_k, t_k) [/itex] in those equations gives you a series of simultaneous equations to solve for [itex] a_i,b_i [/itex]. (You can make up the values of the [itex] t_k [/itex] anyway that satisifes [itex] t_1 < t_2 < ...t_6 [/itex].)

    This is one way out of an infinite number of ways to find a curve through the points and the look of the curve you get this way not please you. To change the look of the curve you have to add more unknown coefficients. To get a unique answer for those coefficients you have to add more conditions. For example, you could pick points on the curve you drew by hand and add them to the data. Or you could specify desired values of the slope of the curve at various points.
  5. Nov 19, 2011 #4
    Looking at the picture, I have to agree with Stephen. That problem is called interpolation. Curve fitting means you try to find a function that is close to those points in the least squares sense.
  6. Nov 19, 2011 #5
    Thanks Stephen and others for the reply. Y is indeed a function of X. The only thing is X is in Log scale and Y is in linear scale. Yup am shooting for a nice formula, which will go through all the points. Since the horizontal axis is in Log scale , how it is going to affect the interpolated formula? Thanks.
  7. Nov 19, 2011 #6

    Stephen Tashi

    User Avatar
    Science Advisor

    Y is not a function of X as you drew the curve. There are some X values for which there are two possible Y values. That can't occur if you want Y to be a function of X.
  8. Nov 19, 2011 #7

    Simon Bridge

    User Avatar
    Science Advisor
    Homework Helper

    This is where, to properly advise you, we need to know what the data represents: what did you measure that you plotted to get that graph? Why were you plotting a lin-log plot - what was this supposed to achieve?

    I suspect that your curve is not supposed to go through all the data points. That's quite unusual.

    For instance - if your data is expected to come from a function of form:
    [itex]y=y_0e^{\lambda x}[/itex]

    and you measure y for set values of x

    then if you plot the natural logarithm of y against x you get a line:
    [itex]\ln|y| = \ln|y_0| + \lambda x[/itex]

    ... with slope and intercept that can be found by least-squares regression (or max/min estimates). The line you get this way is unlikely to pass through any of the data points - expected since the data points are known to be uncertain: they are measurements after all.

    ... covers polynomial interpolation through to curve fitting using matlab or gnu octave.
    Last edited by a moderator: Apr 26, 2017
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook