You are on page 1of 21

Interpolation-Note 2

From a table of x, y data points, it is sometimes


necessary to determine the value of y at an x
value that lies between the tabulated values. This
process of interpolation involves the
approximation of an unknown function. It
depends upon the user to choose a suitable
function. You can use simple linear interpolation
which uses a straight line between two adjacent
points. A large number of methods exist for
interpolation. Although some interpolation
formulae require uniformly spaced x values, all
the methods are applicable to non-uniformly
spaced values
Dr. A. Okullo 1
Lookup and Vlookup functions
Excel provides 3 worksheet functions for
obtaining values from a table: VLOOKUP,
looks up vertically in a table; HLOOKUP,
looks up horizontally in a table. These
two functions are similar and have
identical syntax. The LOOKUP is less
versatile than the others but is often used
where the others have failed.
Syntax: VLOOKUP(lookup_value, table_
array, column_index_num, range_lookup)

Dr. A. Okullo 2
Looks for a match between lookup_value and
values in the leftmost Column of
table_array and returns the value in a
specified column in the row in which the match
was found.
Where:
Lookup_value is the value to be found in the
first column of the array. Lookup_value can be a
value, a reference, or a text string.
Table_array is the table of information in
which data is looked up. Use a reference to a
range or a range name.
Dr. A. Okullo 3
Col_index_num is the column number
in table_array from which the matching
value should be obtained. For example,
a col_index_num of 2 means the match
value should be obtained form the
second column in table_array; a
col_index_num of 3 means the match
value should be obtained from the third
column in table_array, etc

Dr. A. Okullo 4
Range_lookup is a logical value that
specifies whether you want VLOOKUP to
find an exact match or an
approximate match. If TRUE or
omitted, an approximate match is
returned. In other words, if an exact
match is not found, the next largest value
that is less than lookup_value is returned.
If FALSE, VLOOKUP will find an exact
match. If one is not found, the error
value #N/A is returned.
Dr. A. Okullo 5
If range_lookup is TRUE, the values in the first column
of table_array must be sorted in ascending order:
e.g. -2, -1, 0, 1, 2, or A-Z, FALSE, TRUE; otherwise
VLOOKUP may not give the correct value. If
range_lookup is FALSE, table_array does not need to be
sorted.
If VLOOKUP can't find lookup_value, and range_lookup
is TRUE, it uses the largest value that is less than or
equal to lookup_value.
If lookup_value is smaller than the smallest value in the
first column of table_array, VLOOKUP returns the #N/A
error value.
If VLOOKUP can't find lookup_value, and range_lookup
is FALSE, VLOOKUP returns the #N/A value.
Lets try vlookup on the worksheet data given below:

Dr. A. Okullo 6
A B C
1 Density Viscosity Temperature
2 0.457 3.55 500
3 0.525 3.25 400
4 0.616 2.93 300
1 doesnt exist,
next highest 5 0.675 2.75 250
value less than 2.57 200
6 0.746
or equal to 1 is
picked. 7 0.835 2.38 150
8 0.946 2.17 100
9 1.09 1.95 50
10 1.29 1.71 0

Dr. A. Okullo 7
=VLOOKUP(1,A2:C10,2): Looks up 1 in
column A, and returns the value from column B
in the same row (2.17).
=VLOOKUP(1,A2:C10,3,TRUE) Looks up
1 in column A, and returns the value from
column C in the same row (100).
=VLOOKUP(2,A2:C10,2,TRUE) Looks up
2 in column A, and returns the value from
column B in the same row (1.71)
=VLOOKUP(0.525,A2:C10,3,FALSE) Looks
up 0.525 in column A, and returns the value
from column C (400).
Dr. A. Okullo 8
Exercises using Vlookup

The following worksheet table contains


freezing and boiling points of Heat
Transfer fluid. Use Vlookup to return the
viscosity for given %glycol as follows:
Find the freezing point of a 33% solution
of ethylene glycol.
Find the refractive index of a 22%
Ethylene glycol
Find the freezing point of a 15%
Ethylene glycol
Dr. A. Okullo 9
Wt%Ethyl BPt Ref Index
Glycol FPt
0 32 212 1.3328
5 29.4 213 1.3378
10 26.2 214 1.3428
15 22.2 215 1.3578
20 17.9 216 1.353
21 16.8 216 1.354
22 15.9 216 1.3551
23 14.9 217 1.3561
24 13.7 217 1.3572
25 12.7 218 1.3582
26 11.4 218 1.3593
27 1.4 218 1.3603
28 8.2 219 1.3614
29 8 219 1.3624
30 6.7 220 1.3635
31 5.4 220 1.3646
32 4.2 220 1.3656
33 2.9 220 1.3667
Dr. A. Okullo 34 1.4 10
220 1.3678
35 -0.2 221 1.3688
Linear Interpolation

Using Lookup, Match and Index


Excel Functions
Linear interpolation in a table of
data by means of worksheet
formula. To find the value of y at a
point x that is intermediate between
the table values x0, y0 and x1, y1,
use the equation for simple linear
interpolation:
( x x0 )
y y0 ( y1 y0 )
x1 x0

We shall use the example of the


previous lecture.
Dr. A. Okullo 12
Wt%Ethyl Glycol FPt BPt Ref Index
0 32 212 1.3328
5 29.4 213 1.3378
10 26.2 214 1.3428
15 22.2 215 1.3578
20 17.9 216 1.353
21 16.8 216 1.354
22 15.9 216 1.3551
23 14.9 217 1.3561
24 13.7 217 1.3572
25 12.7 218 1.3582
26 11.4 218 1.3593
27 1.4 218 1.3603
28 8.2 219 1.3614
29 8 219 1.3624
30 6.7 220 1.3635
31 5.4 220 1.3646
32 4.2 220 1.3656
33 2.9 220 1.3667
34 1.4 220 1.3678
35 -0.2 221 1.3688
Dr. A. Okullo 13
First we introd. two new excel functions:
MATCH and INDEX to help us use lookup
formula for the interpolation. Match and
index functions are mirror images of each
other. Match looks up a value in an array
and returns its numerical position
whereas Index looks in an array and
returns a value from a specified numerical
position.

Dr. A. Okullo 14
Lets look at how these two functions work.
In a table of production figures for
phosphoric acid, it is desired to find the
month with the highest production. We can
use the Excels Max function to return the
maximum value (83119).
Now to return the month of the maximum,
we can use MATCH to find the position of
the maximum value.
To get the maximum value, click cell B14
and type: =MAX(B2:B13) and enter. Now
use the Match and Index.
Dr. A. Okullo 15
Syntax:
Match(lookup_value,lookup
array,match_type_num)
If match_type_num = 0 it returns the
position of the first value = lookup_value.
For example,
Match(83119,A2:A13,0) returns 4, the
position of 83119.

Dr. A. Okullo 16
Secondly use INDEX to return the
value in the same position in the
array of months. INDEX(A2:A13,4)
returns 83119.

Dr. A. Okullo 17
Month Production
Jan 76212
Feb 15379
Mar 62220
Apr 83119
May 33872
Jun 80881
Jul 54263
Aug 35427
Sep 50361
Oct 71600
Nov 133
Dec 22477

Dr. A. Okullo 18
We can now use Ethylene Glycol Table 1 for interpolation
Position:
Match(Lookup_value,known_xs,1).
Now use Index to locate the values in
positions x0, x1, y0 y1 in the table of
data where we want to interpolate. A (x) B (y)
Lookup value =33.3%
Index(x_values,A2) 1 33.3
Index(x_values,A2+1)
2 33 (x0) 2.9
Index(y_values,B2)
Index(y_values,B2+1) (y0)
B=B2+(A1-A2)*(B3-B2)/A3-A2) or 3 34 (x1) 1.4(y1)
y = y0+(x1-x2)*(y1-y0)/x1-x0

Dr. A. Okullo 19
We can now create a custom function in Visual
Basic Application to interpolate and get the y
value corresponding to x value (33.3%)

Use the VBA to create a custom Interpolation function:


Function InterpL(lookup_value,known_xs,known_ys).
Dim pointer As Integer
Dim x0 As Double, y0 As Double, x1 As Double, y1 As
Double.
Pointer = Application.Match(lookup_value,known_xs,1)
X0 = known_xs(pointer)
Y0= known_ys(pointer)
X1= known_xs(pointer+1)
Y1 = known_ys(pointer+1)
InterpL = Y0 + (lookup_value-X0)*(Y1-Y0)/(X1-X0)
End Function

Dr. A. Okullo 20
After creating your custom function, use it on the
worksheet table just like you would use any in-built
Excel function to do the interpolation. For example,
you would type:
InterpL(lookup_value,known_xs,known_ys) or:
InterpL(33.3,A3:A26,B3:B26)
Check your result and compare with what you got
using the Trend function.

Dr. A. Okullo 21

You might also like