# 1. Linear

 Given two measurement points, linear interpolation gives an estimate of the value one would obtain at other points. Consider the following table of numbers x y 1 2 2 4 3 5  What is the expected value of y at x = 1.6? To answer this, consider the plot of these points. If we assume that un-measured points between x = 1 and x = 2 would fall on a straight line connecting the points at (x1,y1) = (1,2) and (x2,y2) = (2,4), we could compute the parameters m and b in the equation y = mx + b and then plug in the value of x = 1.6. y1 = mx1 + b or 2 = m + b y2 = mx2 + b or 4 = 2m + b Solving for the two unknowns gives 4 = 2(2 − b) + b or b = 0 and m = 2 so the line between these two points is y = 2x; plugging in x = 1.6 gives y = 2 * 1.6 = 3.2. In general, given the points x y x1 y1 x2 y2  the y value, yi, associated with a point xi that is between x1 and x2 is estimated by $y_i = y_1 + (x_i - x_1)\frac{y_2-y_1}{x_2 - x_1}$ An alternative method for finding the unknown value y at x = 1.6 is to use similar triangles. The unknown height is obtained by solving 0.6 / 1.0 = ? / 2.0, or ? = 1.2, so that the y value is 2 + ? = 3.2.

# 2. Bi-Linear

In linear interpolation, one is given pairs of measurement points in the x-y plane and estimates of the y-value are made for a given x-value. For example, if x is position and y represents the measured height of an object, linear interpolation can be used to determine height values at positions for which the height was not measured.

In bi-linear interpolation, one is given values of x,y, and z and asked to estimate z values given x,y values. For example, if x and y represent the position of an object and z represents its measured height, bi-linear interpolation can be used to determine height values at x-y positions where no height measurement was made.

 Bi-linear interpolation requires 3 interpolations. Consider the table of numbers x y z 0 0 2 1 0 1 1 1 0.5 0 1 0.5  Suppose that we want to estimate the value of z at (xo,yo) = (0.25,0,75), which is labeled with an x in the figure. The first interpolation finds a height zA on a line that connects the two points in the x = 0 plane. The second interpolation finds a height zB on a line that connects the two points in the x = 1 plane. The third interpolation finds a height zo on a line that connects zA and zB. The procedure for determining zA, zB, and zo is the same as that for linear interpolation. In general, the bi-linear interpolation expression for zi = f(xi,yi) is $f(x_i,y_i) = \frac{a + b + c + d}{(x_2-x_1)(y_2-y_1)}$ where $\frac{}{}a=f(x_1,y_1)(x_2-x_i)(y_2-y_i)$ $\frac{}{}b=f(x_2,y_1)(x_i-x_1)(y_2-y_i)$ $\frac{}{}c=f(x_1,y_2)(x_2-x_i)(y_i-y_1)$ $\frac{}{}d=f(x_2,y_2)(x_i-x_1)(y_i-y_1)$ and, for example, f(x1,y1) is the height at point (x1,y1)

# 3. Problems

## 3.1. Linear Interpolation

Draw the points in the table and use linear interpolation to find an estimate of z for a=99.5. Show your work using the system of equations method and the similar triangles method.

 a   z
90  20
95  22
100  33


interp1([90,95,100],[20,22,33],99.5)


## 3.2. 1-D Interpolation

An estimate of speed at x = 1.9 given the following measurements

x speed
1 11
2 33


could be made using MATLAB's interp1 function:

Te = interp1([1,2],[11,33],1.9)


Sketch these measurements on a piece of paper, make the calculation of an estimate for speed at x=1.9 by hand using only a calculator, and then compare your result with that from executing the above.

## 3.3. 1-D Interpolation

t  v
1  2.1
2.1 -3.1


Use linear interpolation (pencil and paper) to estimate v at t=1.2.

Use interp1 to verify your answer.

## 3.4. Linear Interpolation

Given an two arrays of measurements x and y write a MATLAB program that, when copied below the code shown, will compute yi, the linearly interpolated value of y at point xi. Your code should work for any value of xi between 1.0 and 4.0.

xi = 1.5;
x  = [1.0,2.0,3.0,4.0];
y  = [1.1,1.8,3.3,4.1];


## 3.5. Linear Interpolation

### 3.5.1. I

Given an two arrays of measurements x and y write a MATLAB program that, when copied below the code shown, will compute yi, the linearly interpolated value of y at point xi. Your code should work for any value of xi between 1.0 and 4.9.

xi = 1.5;
x  = [1.0,2.3,3.1,4.9];
y  = [1.1,1.8,3.3,4.1];


### 3.5.2. II

Use the last pair of (x,y) values to provide an estimate of the value of y at x=5.0.

## 3.6. Linear Interpolation

### 3.6.1. Part I

Given an two arrays of measurements x and y write a MATLAB program that, when copied below the code shown, will compute yi, the linearly interpolated value of y at point xi=1.5. Your code needs to only work the value of xi=1.5.

Do this without using the function interp1.

xi = 1.5;
x  = [1.0,2.1,2.8,3.8];
y  = [2.1,2.8,3.3,8.1];


Write a program that works for any value of xi between 1.0 and 3.8 (without using the function interp1). If I copy the code onto the MATLAB after changing xi, it should give the correct result.

### 3.6.2. Part II

Use the last pair of (x,y) values to provide an estimate of the value of y at x=9.0.

## 3.7. Linear Interpolation

Derive $y_i = y_1 + (x_i - x_1)\frac{y_2-y_1}{x_2 - x_1}$

## 3.8. meshgrid

The function meshgrid can be used to create matrices that are required for the input to interp2.

X  = [1    2;   1   2];
Y  = [1    1;   2   2];


one could write

[X,Y] = meshgrid([1:2],[1:2])


Use both methods to create a grid that corresponds to measurements made in the range of x=2-4 in increments of 0.5 and y=2-3 in increments of 0.5.

Both methods should give the same matrices X and Y.

Save your program as HW5b.m.

## 3.9. Bi-linear Interpolation I

Draw the points in the table and use linear interpolation to find an estimate of z at (x,y)=(0.25,0.75).

x  y  z
0  0  2
1  0  1
1  1 0.5
0  1 0.5


Draw a plot for each of the three linear interpolations and show the calculations required to find zA, zB, and zo.

[X,Y] = meshgrid([0:1],[0:1])
Z = [2.0 1.0;0.5 0.5]
interp2(X,Y,Z,0.25,0.75)


## 3.10. Bi-linear Interpolation II

Suppose that you have the following set of measurements of vx at four grid points and want to estimate vx somewhere inside of the four points.

x   y   vx
1   1   9.9
1   2   10.10
2   1   11.11
2   2   12.12


Sketch out the measurements on a piece of paper and visually attempt to estimate vx at (x,y) = (1.35,1.35).

Write a program that uses interp2 to estimate vx at (x,y) = (1.35,1.35).

Save your program as HW5c.m.

## 3.11. Bi-linear Interpolation II

Suppose that you have the following set of measurements of Bx and By at four grid points and want to estimate Bx and By somewhere inside of the four points.

x   y   Bx   By
1   1   1.1  0.4
1   2   2.2  0.5
2   1   3.3  0.6
2   2   4.4  0.7


Write a program that uses interp2 to estimate Bx and By at (x,y) = (1.35,1.35).

## 3.12. Bi-linear interpolation III

Derive the bi-linear interpolation expression for zi = f(xi,yi):

$f(x_i,y_i) = \frac{a + b + c + d}{(x_2-x_1)(y_2-y_1)}$

where

a = f(x1,y1)(x2xi)(y2yi)

b = f(x2,y1)(xix1)(y2yi)

c = f(x1,y2)(x2xi)(yiy1)

d = f(x2,y2)(xix1)(yiy1)

and, for example, f(x1,y1) is z at point (x1,y1).