# Fitting a curve in log-linear plot.

1. Nov 19, 2011

### mikewinifred

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:

• ###### logLinearFit.png
File size:
10.6 KB
Views:
127
2. Nov 19, 2011

### Simon Bridge

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.

3. Nov 19, 2011

### Stephen Tashi

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
$f(t) = a_0 + a_1 t + a_2 t^2 + ...+a_5 t^5$
$g(t) = b_0 + b_1 t + b_2 t^2 + ...+b_5 t^5$

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

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.

4. Nov 19, 2011

### Charles49

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.

5. Nov 19, 2011

### mikewinifred

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.

6. Nov 19, 2011

### Stephen Tashi

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.

7. Nov 19, 2011

### Simon Bridge

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:
$y=y_0e^{\lambda x}$

and you measure y for set values of x

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

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

Examples:
http://facstaff.unca.edu/mcmcclur/class/LinearII/presentations/html/leastsquares.html
... covers polynomial interpolation through to curve fitting using matlab or gnu octave.

Last edited by a moderator: Apr 26, 2017