views:

109

answers:

5

I am capturing some points on an X, Y plane to represent some values. I ask the user to select a few points and I want the system to then generate a curve following the trend that the user creates. How do I calculate this? So say it is this:

Y = dollar amount X = unit count

user input: (2500, 200), (4500, 500), (9500, 1000)

Is there a way I can calculate some sort of curve to follow those points so I would know based off that selection what Y = 100 would be on the same scale/trend?

EDIT: People keep asking for the nature of the curve, yes logarithmic. But I'd also like to check out some other options. It's for pricing the the restraint is that the as X increases Y should always be higher. However the rate of change of the curve should change related to the two adjacent points that the user selected, we could probably require a certain number of points. Does that help?

EDIT: Math is hard.

EDIT: Maybe a parabola then?

+2  A: 

The Least Square Fit would give you a nice data matching curve.

Michael Dorgan
This kind of begs the question: fitting what function?
walkytalky
+1  A: 

This is a rather general extrapolation problem. In your case, fitting a quadric (parabola) is probably the most reasonable course of action. Depending on how well your data fits a quadric, you may want to fit it to more than 3 points (the noisier and weirder the data, the more points you should use).

AVB
+1 for the extrapolation link, but I'm not sure your choice of polynomial has much justification...
walkytalky
@walkytalky (1) For extrapolation, the lower the order the better (this is even mentioned in the same Wiki article). (2) Without any other information, "curve" usually means "smooth-looking curve". Together, this means that parabola is the best choice (again, unless and/or until you know more about the problem).
AVB
@AVB: Why parabola would be the best choice over, say, logarithm or square root or hyperbole?
nico
+2  A: 

First, you are going to have to have an idea of what your line is or better said, what type of line fits your data the best. Is it linear (straight line) or does it curve (x-squared). Sounds like this is a curve.

If your curve is a parabola, then you will need to solve y = Ax(2) + Bx + c using your three points that the user has chosen. You will need at least 3 points to solve for 3 unknowns.

  1. 200 = A(2500)(2) + B(2500) + C
  2. 500 = A(4500)(2) + B(4500) + C
  3. 1000 = A(9500)(2) + B(9500) + C

Given these three equations, you should be able to solve for A, B and C, then use these to plot a new curve.

Tommy
thanks I'm going to give this a go
shogun
+1  A: 

Depending on the amount and type of data you have, you may want to try LOESS regression.

However, this may not be a good option if you only have 3 points as in your example (but keep in mind that you will not be able to have good extrapolation with 3 points no matter the algorithm you use)

Another option would be B-splines

nico
+3  A: 

The problem is that there are multiple curves that you can fit to the same data. To borrow an example from my old stats book, here is the same data set (1, 1, 1, 10, 1, 1, 1) with four curves:

Curves

You need to specify the overall trend to get a meaningful result.

fatcat1111
+1 for the very clear visual example
nico