Thread: Wrting a lookup func and a lookup table

  1. #1
    Registered User
    Join Date
    Nov 2016
    Posts
    1

    Wrting a lookup func and a lookup table

    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.

  2. #2
    Registered User
    Join Date
    Jun 2015
    Posts
    1,640
    It looks like your interface should be
    Code:
    float lookup(float xi[], float yi[], float x);
    It looks like the idea is to find where x would fit in xi (between what two numbers) and then interpolate from yi (presumably linearly).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Lookup Table Problem
    By danlee58 in forum C Programming
    Replies: 6
    Last Post: 07-22-2014, 04:11 AM
  2. Lookup table help
    By Ducky in forum C++ Programming
    Replies: 10
    Last Post: 10-27-2011, 12:52 PM
  3. lookup table mappings
    By robi in forum C Programming
    Replies: 5
    Last Post: 10-19-2011, 12:25 PM
  4. Making a lookup table?
    By username101 in forum C Programming
    Replies: 7
    Last Post: 05-09-2008, 09:10 AM
  5. using a shared lookup table
    By zxcv in forum C Programming
    Replies: 1
    Last Post: 02-21-2008, 12:10 AM

Tags for this Thread