+ Reply to Thread
Results 1 to 11 of 11

How to perform a linear interpolation in Excel

  1. #1
    Registered User
    Join Date
    05-21-2016
    Location
    Aarhus, Denmark
    MS-Off Ver
    2016
    Posts
    37

    How to perform a linear interpolation in Excel

    Hi,
    I'm trying to do a very simple thing - but I fail...
    I have an array of data (x and y).
    I have a x value that does not match exact to my data point, so I would like to do a linear interpolation between the two points closest to my value (i.e. upper and lower) and return the interpolated y value.
    It sounds simple to my ear - but i cannot make it work. My data are in ascending order. I have tried VLOOKUP and INDEX/MATCH just to find the relevant two y-values but are having problems to find both the lower value and the upper value (as MATCH wants the data to be en ascending order to find lower value and desending to find upper - I think).

    So in short - how do I perform a simple linear interpolation in excel ?

    Value 2,3

    X Y
    1 10
    2 20
    3 30
    4 40
    5 50

    Find y corresponding to x = 2,3



    Kind Regards Torben
    Last edited by TRT; 03-17-2019 at 05:57 AM.

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,367

    Re: Interploate...

    Administrative Note:

    We would very much like to help you with your query, however the thread title does not really convey what your request is about.
    Please take a moment to amend your thread title. Make sure that the title properly explains your request. Your title should be explicit and not be generic (this includes function names used without an indication of what you are trying to achieve).

    Please see Forum Rule #1 about proper thread titles and adjust accordingly. To edit the thread title, open the original post to edit and then click on Go Advanced (bottom right) to access the area where you can edit your title.

    (Note: this change is not optional. No help to be offered until this moderation request has been fulfilled.)
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  3. #3
    Registered User
    Join Date
    05-21-2016
    Location
    Aarhus, Denmark
    MS-Off Ver
    2016
    Posts
    37

    Re: Interploate...

    Sorry about that - tried to adjust it. Hope it's more accurate now :-)

  4. #4
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,367

    Re: How to perform a linear interpolation in Excel

    That's better.

  5. #5
    Forum Expert Roel Jongman's Avatar
    Join Date
    03-28-2015
    Location
    Netherlands
    MS-Off Ver
    Office 365
    Posts
    1,483

    Re: How to perform a linear interpolation in Excel

    I always find "manual interpolation" much easier than putting it in an excel formula. but it is doable. vlookup gets me stuck to easy, using index and match helps me to solve.

    just to help understand the values a bit better I have put X and Y values in col x and y cols so you can read in the formula if x or y value is used in which part

    so that resulted in

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    MATCH(AA3;$X$2:$X$6;1) finds the values closest but always less then the desired value.
    MATCH(AA3;$X$2:$X$6;1)+1 simply finds the next row in the value that will be over the wanted x

    the index parts in the formula helps to eighter use the X value or the Y value in the formula

    if you translate each index to its value it will show..

    X to find Y value for in my example is 2,25 (in cell AA3 for this example) this will result in the following outcome for each index formual above

    y= 20 + ((2,25-2)*(30-20)/(3-2))

    y = 20 + 0,25*10

    y = 22,5



    The formula could be simplified somewhat if the interval of x values is always 1 but because changes are this is not always the case this formula will work on any interval. To help understand the formula you can also use the evaluate formula option under formulas menu in the Formula Auditing section (3rd or 4th section on the ribbon)
    Attached Files Attached Files
    Last edited by Roel Jongman; 03-17-2019 at 06:49 AM. Reason: added explantion on parts of the formula

  6. #6
    Forum Expert José Augusto's Avatar
    Join Date
    10-29-2014
    Location
    Portugal
    MS-Off Ver
    2013-2016
    Posts
    3,329

    Re: How to perform a linear interpolation in Excel

    Or try this formula

    Formula: copy to clipboard
    Please Login or Register  to view this content.

    where A1, B1 are labels, A2:A6 are the x_values, B2:B6 the y_values and D2 the x you want to get.

    Note: Formula is valid to x in [A2, A6[
    You must indicate the office version not the operating system.

  7. #7
    Registered User
    Join Date
    05-21-2016
    Location
    Aarhus, Denmark
    MS-Off Ver
    2016
    Posts
    37

    Re: How to perform a linear interpolation in Excel

    @Roel
    Thanks a lot. I would never have solved this :-)

  8. #8
    Registered User
    Join Date
    05-21-2016
    Location
    Aarhus, Denmark
    MS-Off Ver
    2016
    Posts
    37

    Re: How to perform a linear interpolation in Excel

    @José
    I can not make your suggestion work. I can't see B2:B6 in your formula, instead you have twice A1:A6. Is that correct ??

  9. #9
    Registered User
    Join Date
    05-21-2016
    Location
    Aarhus, Denmark
    MS-Off Ver
    2016
    Posts
    37

    Re: How to perform a linear interpolation in Excel

    @Jose
    Sorry, it works. Just still can't see the ref. to B2:B6? (but it's working nicely). Is it a truly linear fit ?

  10. #10
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,810

    Re: How to perform a linear interpolation in Excel

    When these questions come up, I sometimes wish that QuattroPro was still around. QuattroPro had a nice, built in @LINTERP() function that made short, easy work of linear interpolation problems.

    As a different alternative, I find that I prefer to not try to do linear interpolation in a single cell formula. I prefer to spread it out. Compute slope and intercept for each segment in helper columns adjacent to the original data "lookup table". Then the linear interpolation becomes something simpler =VLOOKUP(known_x,lookup_table,intercept_column,TRUE)+x*VLOOKUP(known_x,lookup_table,slope_column,TRUE). I've illustrated this in this old thread: https://www.excelforum.com/excel-cha...e-a-curve.html
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  11. #11
    Forum Expert José Augusto's Avatar
    Join Date
    10-29-2014
    Location
    Portugal
    MS-Off Ver
    2013-2016
    Posts
    3,329

    Re: How to perform a linear interpolation in Excel

    Yes, is a true linear fit because it's use only two values for x and two for y.

    B2:B6 can be referred by OFFSET(B1,1,0,5,1).

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1