+ Reply to Thread
Results 1 to 6 of 6

Linear interpolation based on hardcoded data pairs?

  1. #1
    Registered User
    Join Date
    03-26-2009
    Location
    New Jersey
    MS-Off Ver
    Excel 2007
    Posts
    26

    Linear interpolation based on hardcoded data pairs?

    I'd like a linear interpolation function that calculates the linear interpolation based on a data set hardcoded within the function itself - rather than data present in a worksheet table.

    For instance given the following:
    Please Login or Register  to view this content.
    The function call =interpolate(1.5) would give a result of 6.5, =interpolate(3.25) would give 2.375.

    How would I perform this?

  2. #2
    Valued Forum Contributor Steffen Thomsen's Avatar
    Join Date
    10-15-2010
    Location
    Kolding, Denmark
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    953

    Re: Linear interpolation based on hardcoded data pairs?

    Hi,

    You have to deduct the linear formula

    Example

    y = x^2 + x + 1

    Then you write the function

    Please Login or Register  to view this content.
    Afterwards you can call the function.

    Steffen Thomsen

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

    Re: Linear interpolation based on hardcoded data pairs?

    When I switched from Quattro Pro to Excel, this was one of the things I missed the most -- a built in linear interpolation function.

    I think that the hardest part of linear interpolation is extracting the interval containing the unknown. I would probably use the MATCH function. In another part of the spreadsheet
    Please Login or Register  to view this content.
    which will return the location i in the table of the interval. Then
    Please Login or Register  to view this content.
    to build a new table containing x1,y1 and x2, y2. Then, you can use either TREND or the point slope formula or whatever to locate new_y

  4. #4
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Linear interpolation based on hardcoded data pairs?

    How would this work if the data were hardcoded? In your example you would need to pass five arguments, no?

  5. #5
    Registered User
    Join Date
    03-26-2009
    Location
    New Jersey
    MS-Off Ver
    Excel 2007
    Posts
    26

    Re: Linear interpolation based on hardcoded data pairs?

    Quote Originally Posted by Steffen Thomsen View Post
    Hi,

    You have to deduct the linear formula

    Example

    y = x^2 + x + 1
    Sorry, but I am not following? Is this interpolation or something else?
    Quote Originally Posted by MrShorty View Post
    to build a new table containing x1,y1 and x2, y2.
    Thank you, but I am looking for something where the raw data is hardcoded into the function and not passed from a table. I'm not sure what the best way to hardcode the data would be - the only way I'm familiar with is Arrays, but perhaps someone can mention something else. But I'd be thinking something like for instance:
    Please Login or Register  to view this content.
    Question: If I try to use Double as the array type I get a #VALUE! error, instead I have to use variant - why is this?

    Here's the interpolation function I've written - feedback and improvements are welcome
    Please Login or Register  to view this content.

  6. #6
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Linear interpolation based on hardcoded data pairs?

    why is this
    Because that's how you declare that sort of array! I know that sounds circular but it's just a rule for an array declared in that way. You could make it marginally shorter by removing the loop:
    Please Login or Register  to view this content.

+ 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