So for a homeowrk assignment we were studying y=m*x+b; linear equation. We had to write it as a function and test it out by inputing x and y values.
However for the second part, we were asked to write a float lookup function that takes in two arrays (x and y).
As I quote the question.
"Write a new float function called lookup for your interp.c file that takes two floatarrays and a float number as arguments. The first array will contain xi and the second willcontain the corresponding yi values. The float number given is the x value for which aninterpolated result is desired. You will need to write code to locate the index, i, such that1xi < x < xi+1. Keep your code general, without making any assumptions about the values, xi,other than that they are increasing order."
So far this is what I have;
Insert
Code:
float lookup(float x[], float y[], float n, float N)
Code:
int i;
float x1,x2,y1,y2,y;
float x[] = { 0, 1, 2, 3, 4 };
float y[] = { 7, 7.75, 10, 13.75, 19 };
x[] and y[] just refers to the arrays and n is the intermediate x value, where N is the final y value.