Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

How to derive a function from an irregular table of values?

  1. Mar 12, 2014 #1
    It's easy to get a function from a table that follows a clear pattern, but what if the values for y (or x) don't follow a pattern? For example;

    x = 1 , y = 13
    x = 2 , y = 9
    x = 3 , y = 3
    x = 4 , y = 8
    x = 5 , y = 1
    x = 6 , y = 5
    x = 7 , y = 12

    If you look at these points on a graph, they don't make any normal line.
  2. jcsd
  3. Mar 12, 2014 #2
    You should be able to fit a 6th degree polynomial that goes through all those points. You can do this using the LINEST function in Excel.
  4. Mar 12, 2014 #3
    I put the values into excel and did =LINEST(A2:A8,B2:B8,,FALSE) and it gave me -0.464285714 as the slope and 9.142857 as the y-intercept but that can't be right, so I must have done something wrong... I'm not great with excel.
  5. Mar 12, 2014 #4
    Yes, you want a 6th degree polynomial not a one degree polynomial:

    ax^6 + bx^5 + cx^4 + dx^3 + ex^2 + fx + g

    You will probably need to research to figure out how to get Excel to do this for you.
  6. Mar 13, 2014 #5


    User Avatar
    Education Advisor

  7. Mar 13, 2014 #6


    User Avatar
    Science Advisor

    If the points do not have a pattern then a function that you determine by fitting it to match those seven points will not have much pattern either. Getting Excel to give you a degree six polynomial that passes through seven points will not give you a reasonable prediction for the eighth...

    ...unless you have reason to believe that the underlying data is not random and actually came from a sixth degree polynomial in the first place.
  8. Mar 14, 2014 #7
    You're right, but I think what I'm looking for is an equation that will equal the values of y when you plug in the corresponding values of x. Plugging in 1 will give you 13, 2 will give you 9, and so on :P.
  9. Mar 14, 2014 #8


    User Avatar
    Education Advisor

  10. Mar 14, 2014 #9
    Wow! That's exactly what I was looking for... Although I don't quite understand Lagrange Interpolation. Thanks!
  11. Mar 15, 2014 #10


    User Avatar
    Science Advisor

    One way to think about it is that you have seven known values -- your data points. Now find seven different functions that have values at each of those data points. You need to pick functions that are linearly independent. That is, no one function can turn out to match any sum of multiples of the other functions.

    Call the functions f1, f2, f3, f4, f5, f6 and f7.

    You want to put together a combination k1f1 + k2f2 + k3f3 + k4f4 + k5f5 + k6f6 + k7f7 such that the combination has the right values at each of your seven data points. You can find the right combination by solving a set of seven simultaneous equations in seven unknowns. Say your data points are (x1,y1) through (x7,y7)

    Then the equations are:

    y1 = k1f1(x1) + k2f2(x1) + ... + k7f7(x1)
    y2 = k1f1(x2) + k2f2(x2) + ... + k7f7(x2)
    y7 = k1f1(x7) + k2f2(x7) + ... + k7f7(x7)

    You know all the x's and y's. Those are your data points. You know the values for each of the functions at each of the x's. That's just a matter of evaluating each function at each point. The k values are the unknowns. Solve for for k1 through k7

    Lagrange Interpolation is what you get if you take f1 through f7 to be:

    f1(x) = 1
    f2(x) = x
    f3(x) = x2
    fn(x) = xn-1

    [Edit, fixed error on the final exponent above]

    Obviously this will work for any number of data points, not just seven.
    Last edited: Mar 15, 2014
  12. Mar 15, 2014 #11
    That is what the excel function is doing except it does a least squares approach for the case where the number of data points exceeds the degree of the polynomial by one or more.
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted

Similar Discussions: How to derive a function from an irregular table of values?