Return to my Mathematics pages
Go to my home page


Interpolation

© Copyright 2001, Jim Loy

Using trig tables, I would like to find the tangent of 42.5 degrees. These values come from the tables:

41     0.86929
42 0.90040
43 0.93252
44 0.96569

linear interpolationTo estimate the tangent of 42.5 degrees, we would normally just interpolate linearly. 0.93252-0.90040=0.03212. Since we are trying to find the value midway between 42 and 43, we just divide this interval in half: 0.01606 and add that to 0.90040, and get 0.91646. The actual value is 0.91633. So we are fairly close.

Linear interpolation involves approximating a curve with a straight line. In the diagram, we know the coordinates (x1,y1) and (x2,y2). And we want to find the y value for x. If, in the above example, we wanted to find the tangent of 42.2 degrees, we would multiply the difference 0.03212 by 0.2 and get 0.006424. Adding that to 0.90040, we get 0.90682 (dropping the sixth digit, which was wasted precision). The actual value of tan(42.2) is 0.90674. Again, this is fairly close.

cubic or quadratic interpolationOf course, we can do better than that. We can actually approximate a curve with another curve, one that we can calculate to any desired precision. Smoothing of data points is often done with a cubic spline. This just involves drawing a cubic equation (y=ax^3+bx^2+cx+d, where x^3 is x cubed) through each pair of points. Which cubic equation should we choose? We just choose the cubic equation that goes through the two points, and the two points on either side of those two points. Four points determine a cubic equation. So, if we have 7 points, we end up with 5 cubic equations. The two end intervals share cubic equations with their neighboring intervals. These cubic equations can be used to interpolate between any of the known points.

It is somewhat easier (and about as accurate) to interpolate using a quadratic equation (y=ax^2+bx+c). Then we only need three known points. I will estimate the tangent of 42.2 degrees. From our table, I will choose (41,0.86929), (42,0.90040), and (43,0.93252). I could make the arithmetic easier, by translating the graph left, right, up, or down, or by changing the scale; but I won't.

      y=ax^2+bx+c
0.86929=1681a+41b+c
0.90040=1764a+42b+c
0.93252=1849a+43b+c

There are several ways to solve for a, b, and c. I will just subtract equations:

0.03212=85a+b
0.03111=83a+b
-------------
0.00101=2a

Solving for a, and then b, and then c, we get a=0.000505, b=-0.010805, and c=0.463390 (with one digit of extra accuracy). Then we can solve y=0.000505x^2-0.010805+0.463390 for x=42.2. Then y=0.906743. The 3 is too accurate; so the answer is 0.90674. That is extremely accurate.


Return to my Mathematics pages
Go to my home page