Solve for missing values using linear interpolation

654 Views Asked by At

I have been tasked with trying to find a launch angle for a pumpkin launcher for a competition with a club at school! I am given the following data in a table and my goal is to find the launch angle to achieve a certain range given a distance and weight.

Basically I have written the program to obtain the two tables, the lower and upper weight tables. (There are many different tables based on the weight, I currently just wrote out the two that correspond to the weight of the pumpkin).

The lower weight represents the data I have for the closest weight below the target pumpkin, and upper weight data represents data I have for the closest weight above the target pumpkin.

Given these two tables I then grab the two angles that are above and below the target range for each of the weight tables.

So given the following information, how do I solve for theta given a weight I don't have a table for.

I am given the weight and Target distance, and the weight above and below of the given weight, and the corresponding angles. Basically everything on the left is given.

The pencil represents actual values for the problem from the table in the top right.

Input: target_weight (weight of the launched pumpkin), target_distance (how far we want the pumpkin to go)

Extracted:

  • lower_weight = the table generated by the lower weight pumpkin
  • upper_weight = the table generated by the upper weight pumpkin
  • lower_weight_lower_angle = the angle whose distance is below the target
  • lower_weight_lower_angle = the angle whose distance is above the target
  • upper_weight_lower_angle = the angle whose distance is below the target
  • upper_weight_lower_angle = the angle whose distance is above the target

Tables:

$$\large\begin{array}{cc} {2\:\text{lbs}}\over {\begin{array}{c|c} 10^\circ & 274\:\text{ft} \\ \hline 15^\circ & 328\:\text{ft} \\ \hline 20^\circ & 366\:\text{ft} \\ \hline 25^\circ & 390\:\text{ft} \\ \hline 30^\circ & 404\:\text{ft} \\ \hline 35^\circ & 410\:\text{ft} \end{array}} & {3\:\text{lbs}}\over{\begin{array}{c|c} 10^\circ & 284\:\text{ft} \\ \hline 15^\circ & 353\:\text{ft} \\ \hline 20^\circ & 404\:\text{ft} \\ \hline 25^\circ & 440\:\text{ft} \\ \hline 30^\circ & 462\:\text{ft} \\ \hline 35^\circ & 473\:\text{ft} \end{array}} \end{array}$$

Output: launch_angle (angle necessary to launch the specific weight pumpkin a certain distance)


Example:

Input:

  • 2.5 lbs
  • 400 ft

Output:

  • launch_angle

lower_weight = 2 lbs

  • lower_weight_lower_angle = 25$^\circ$
  • lower_weight_upper_angle = 30$^\circ$

upper_weight = 3 lbs

  • upper_weight_lower_angle = 15$^\circ$
  • upper_weight_upper_angle = 20$^\circ$

$\large\star$ 8 variables: 2 input, 6 generated

1

There are 1 best solutions below

0
On BEST ANSWER

Short answer: Linear interpolation isn't going to work very well.

Long answer: Quadratic interpolation will work much better. Both sets of data you have are nearly perfectly represented by quadratic functions, which I've calculated in this Desmos graph. Here's what I found for your example with target_weight = $2.5$ lbs and target_distance = $400$ ft:

enter image description here

In this case, you'd need to launch the $2.5$ lb pumpkin at an angle of $22.24^\circ$.


The red parabola is the parabola of best fit for the data set in the $3$ lbs table, and the green parabola is that of the data set in the $2$ lbs table. The blue parabola between them is a weighted average of the other two parabolas: essentially a prediction of what the parabola of best fit for $2.5$ lbs would look like.

In this case, rather, the blue parabola is the exact average of the red and green parabolas (because $2.5$ is exactly halfway between $2$ and $3$), but in general, I've set it up to be possible to weight them differently to obtain a prediction of what the best-fit parabola for, say, $2.75$ lbs would look like. You can account for that in the graph by adjusting $t_w$, which is the target weight. You can even set it to be something outside the range of $2$-$3$ lbs. $t_d$ is the target distance, and you can adjust that and $t_w$ to find the desired launch angle.

It's worth noting that this model ignores the effects of air resistance, so it's far from perfect, but it should at least get your pumpkins pretty close to where they need to go.