User Tools

Site Tools


supp:excel_for_scientists:interpolation

This is an old revision of the document!


Interpolation

Linear

VBA Function

Option Explicit

' Linear Interpolation function from the companion CD 
' of the book "Excel for Scientists" by Billo.
Function InterpolateL(lookup_value, known_xs, known_ys)

  Dim pointer As Integer
  Dim X0 As Double
  Dim Y0 As Double
  Dim X1 As Double
  Dim Y1 As Double

  'Following line added to prevent extrapolation
  If lookup_value < Application.Min(known_xs) Or lookup_value > Application.Max(known_xs) Then
    InterpolateL = CVErr(xlErrRef): Exit Function
  End If
  
  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)
  InterpolateL = Y0 + (lookup_value - X0) * (Y1 - Y0) / (X1 - X0)
End Function

Data

"Freezing and Boiling Points
 of Heat Transfer Fluid"	
"Wt% 
Ethylene 
Glycol"	Freezing Point, °F
0.0     	32.0     
5.0     	29.4     
10.0     	26.2     
15.0     	22.2     
20.0     	17.9     
21.0     	16.8     
22.0     	15.9     
23.0     	14.9     
24.0     	13.7     
25.0     	12.7     
26.0     	11.4     
27.0     	10.4     
28.0     	9.2     
29.0     	8.0     
30.0     	6.7     
31.0     	5.4     
32.0     	4.2     
33.0     	2.9     
34.0     	1.4     
35.0     	-0.2     
36.0     	-1.5     
37.0     	-3.0     
38.0     	-4.5     
39.0     	-6.4     
40.0     	-8.1     
41.0     	-9.8     
42.0     	-11.7     
43.0     	-13.5     
44.0     	-15.5     
45.0     	-17.5     
46.0     	-19.8     
47.0     	-21.6     
48.0     	-23.9     
49.0     	-26.7     
50.0     	-28.9     
51.0     	-31.2     
52.0     	-33.6     
53.0     	-36.2     
54.0     	-38.8     
55.0     	-42.0     
56.0     	-44.7     
57.0     	-47.5     
58.0     	-50.0     
59.0     	-52.7     
60.0     	-54.9     
supp/excel_for_scientists/interpolation.1448535993.txt.gz · Last modified: 2015/11/26 11:06 by admin