Sunteți pe pagina 1din 2

Implementing Interpolation with Microsoft Excel

The linear interpolation equation above can be implemented directly in Microsoft Excel
provided the tabulated values are monotonic in x, that is the x-values are sorted and no
two are equal. The online Microwave Encyclopedia has the full 6 line implementation
along with a good explanation of how it works.
However, here is a simpler implementation for Excel:
=FORECAST(NewX,OFFSET(KnownY,MATCH(NewX,KnownX,1)1,0,2),OFFSET(KnownX,MATCH(NewX,KnownX,1)-1,0,2))
To use it either:
1.

Copy the formula above into Excel and replace KnownX and KnownY with the cell
reference for the tabulated x and y values and NewX with the x-value to interpolate, OR
2.
Define names for the KnownX and KnownY ranges (InsertNameDefine... in
Excel 2003) and replace NewX with the x-value to interpolate.
You can download the Excel linear interpolation example.
This equation works exactly the same way as the direct implementation of the linear
interpolation equation. The main difference is that only two lookup functions are
required for the simple approach described here, while the direct implementation needs
6: one for each term in the equation.

How the Excel implementation works


The simple implementation is easiest to understand by dissecting from the outside and
working in. Here's the full equation:
=FORECAST(NewX,OFFSET(KnownY,MATCH(NewX,KnownX,1)1,0,2),OFFSET(KnownX,MATCH(NewX,KnownX,1)-1,0,2))
In brief, the equation consists of 3 parts:
1.
2.

the FORECAST function to calculate the linear interpolation,


two calls to the MATCH function to find the tabulated x-value closest too, but less
than the new-x value, and
3.
two calls to the OFFSET function to reference the tabulated x-values and y-values
just above and just below the new-x value.
In more detail, the FORECAST function performs the actual interpolation using the linear
interpolation equation shown above. Its syntax
is: FORECAST(NewX,known_y_pair, known_x_pair).
The first parameter, NewX is simply the value to interpolate. The next two
parameters, known_y_pair and known_x_pair are the values either side of NewX.
That is, {x1, x2} and {y1, y2} in the diagram above.
The MATCH function is used to find the tabulated x-value just below NewX. Its syntax
is: MATCH(lookup_value, lookup_table,match_type). MATCH returns the relative
position of an item in a sorted array. So, lookup_value is the value to
interpolate, lookup_table is the array of KnownX values, and match_type is 1 to find
the largest value in the array that is less than or equal to NewX.
The MATCH function returns an index, but the FORECAST function requires two cell
ranges: one for the known_x_pair and one for the known_y_pair. So,

theOFFSET function is used twice to create these ranges. Its syntax


is OFFSET(reference, row_offset, column_offset, row_count,column_coun
t). It takes a starting point, the reference, and creates a cell reference with the given
offset and size. To obtain the known_y_pair range, the reference is set to the table
of KnownY values; for the known_x_pair range, reference is set to the array
of KnownX values. If the tabulated values are arranged vertically, the row_offset is the
result from the MATCH function less 1 and row_count is 2; column_offset is 0
and column_count is 1. This gives us a cell array reference 2 cells high and 1 cell wide.
If the tabulated values are arranged horizontally, row and column are switched in
the OFFSET function.

Linear Interpolation In Excel


There are many ways to perform linear interpolation (or extrapolation) in Excel. The
examples below assume that you know at least two points (x 1,y1) and (x2,y2) and
want to solve for y given x based on the equation for a line: y=mx+b, where m is
the slope and b is the y-intercept.

1. Using the Point-Slope formula, where the slope is (y 2-y1)/(x2-x1):


y=y1+(x-x1)*(y2-y1)/(x2-x1)
=B2+(B5-A2)*(B3-B2)/(A3-A2)

2. Using the SLOPE and INTERCEPT functions to solve for m and b:


y=SLOPE(y's,x's)*x+INTERCEPT(y's,x's)
=SLOPE(B2:B3,A2:A3)*B5+INTERCEPT(B2:B3,A2:A3)

3. The TREND function uses linear regression to solve for y if you have two or more
points. This is also a way to estimate y from a linear fit of many points.
y=TREND(y's,x's,x,TRUE)
=TREND(B2:B3,A2:A3,B5,TRUE)

S-ar putea să vă placă și