+ Reply to Thread
Results 1 to 5 of 5

Linear interpolation helps

  1. #1
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,436

    Linear interpolation helps

    Linear interpolation is a somewhat common question that comes up on the forums, and I see a few different ways people approach it. With my recent "upgrade" to the 2024 version of Excel, I decided to make my first LAMBDA() UDF attempt to be for linear interpolation. Then I decided to post it here as a possible help for others. I don't want to claim that my approach here is the only or the best approach, so, if anyone has their own offering to make, please feel free to add it.

    The LAMBDA() function I came up with is this:
    Please Login or Register  to view this content.
    I structured the function call to be basically the same as the TREND() function and Gnumeric's INTERPOLATION() function. Simply assign the function to a name in the name manager, and you have a UDF that you can call that will do linear interpolation.

    One note. As currently programmed, the function assumes that your "known_x" values are sorted in ascending order (see the optional toggles in the XMATCH() functions). It also returns an error if your newx value is outside of the range of knownx values (it only does interpolation, it won't do extrapolation).

    Usage is illustrated in the attached file. I've also included the old strategy for interpolation that I have recommended over the years.

    Hopefully it is helpful for others. Feel free to add your strategies for linear interpolation to give users different options.
    Attached Files Attached Files
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

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

    Re: Linear interpolation helps

    Thanks for sharing.
    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. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

  3. #3
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,436

    Re: Linear interpolation helps

    A couple of days later, and I notice something else about this. For those who have enthusiastically embraced "spill" formulas, this interpolation function doesn't spill correctly. If you give it multiple newx values, it will not perform the interpolation correctly. It will return multiple results, but the results won't be correct. The old style "program one cell for one result then copy/paste to get multiple results" that has dominated spreadsheet programming for 40+ years is so engrained in me that I didn't think to worry about how the function would behave under "program one cell to get multiple results" paradigm. I don't immediately see a way to make this function spillable, but I do note that the "old strategy" readily spills =VLOOKUP(P8:P15,$K$7:$N$19,4,TRUE)+VLOOKUP(P8:P15,$K$7:$N$19,3,TRUE)*P8:P15. Maybe something that doesn't use the TREND() function to perform the final interpolation would work.

  4. #4
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,436

    Re: Linear interpolation helps

    Here's a lambda function that will spill correctly
    Please Login or Register  to view this content.
    The TREND() function was the reason it wouldn't spill correctly, so I ended up completely eliminating the TREND() function from the formula. The "downside" is that this version requires 7 lookups, where the prior version only required 4 lookups. They are binary search lookups, so they should be fast, but there is more duplicated lookup effort in this version than the post #1 version. There are also a lot more parentheses in this one, which makes it harder to keep track of which parentheses go where.

  5. #5
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,436

    Re: Linear interpolation helps

    Here's a version that will spill correctly, and I figured out how to put the calculation inside of a LET() function so that the lookup step only occurs once (in theory, anyway):
    Please Login or Register  to view this content.
    Last edited by MrShorty; 04-14-2025 at 02:40 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Linear Interpolation
    By cl6120 in forum Excel General
    Replies: 4
    Last Post: 07-10-2020, 12:20 AM
  2. Interpolation, non linear. Need help please.
    By traumerei1838 in forum Excel General
    Replies: 8
    Last Post: 08-12-2015, 01:04 AM
  3. [SOLVED] how to do linear interpolation
    By fight2 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 03-11-2015, 08:40 PM
  4. Linear Interpolation help
    By jsuarez199 in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 10-21-2013, 03:12 PM
  5. Linear Interpolation
    By mikethemonster in forum Excel General
    Replies: 0
    Last Post: 07-04-2011, 02:27 PM
  6. VBA Linear Interpolation
    By WAW in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-25-2010, 04:55 PM
  7. Linear Interpolation
    By Metalmaniac in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 06-03-2005, 10:05 AM

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