Assignment #4 - 91A

Assignment #4 - 91A


!! Note updated 12 February   ===   Extension to 28th February !!
308-208: Introduction to Computer Science for Engineers Assignment 4

TA: Alan Ezust   E-mail assignments ONLY to-> HQKD
Office Hours: Mondays 2:00-3:30  McConnell Room 333

NOTE: For questions, complaints, or comments, send e-mail to
      depeche@cs.mcgill.ca.

Assignments sent to depeche will be ignored.
Questions/comments sent to HQKD will also be ignored.

THE MARKING SCHEME:

Assignments are marked out of 20.
The weight of this assignment is 35.
Copied assignment are marked out of 10.
No program output: -7.
Incomplete Source listing (i.e. no data): -3.
This assignment is due by 28th February  << == NOTE Extension !!!
                          =============
THE BACKGROUND:

One very primitive numerical method for estimating values of functions when
given discrete data points which form a curve similar to that function is
LINEAR INTERPOLATION.

In a wind tunnel, one measures lift and drag forces generated by moving air
streams on an aerodynamic body. With enough data collected, it should be
possible to have a fairly good idea of the lift coefficient given a flight
path angle which is in between the sampled points. Linear Interpolation is
the method used for this.

THE ASSIGNMENT:

FPA = Flight Path Angle. CoL = Coefficient of Lift.
Your input data is as follows:

      FPA   CoL
      -4    -0.202
      -2    -0.050
      0     0.108
      2     0.264
      4     0.421
      6     0.573
      8     0.727
      10    0.880
      12    1.027
      14    1.150
      15    1.195
      16    1.225
      17    1.244
      18    1.250
      19    1.245
      20    1.221
      21    1.177

Your program should work for any set of data as long as the FPA is input in
ascending order. If the program reads an FPA which is less than the
previous FPA read, it should output an error, and exit. (for bonus marks:
can you explain what would be required for the program to work properly if
it allows for the data points to be read in any order?)

The program and output you submit to me should be run with the above sample
data!

After the sampled points are read (into an array, presumably), the program
must read a list of AT LEAST 5 FPA values. Using linear interpolation, it
should estimate the CoL, and output that. In addition, the program should
output the data points, and their indices in the array, which were used to
calculate your estimated value of CoL.

For your submission, two of the >4 FPA values you will test for input must
be 5.0 and 20.65. The other values you can choose from the given range.

THE MATHEMATICS:

An estimation (est) based on linear interpolation is defined as follows:
      Given a function f only defined on discrete points, and we wish to
      estimate f(x), where x was entered by the user (or from the data),

  If f(x) is defined, est = f(x).
  If x is not between two of the sampled points, output a "range error".
  If x is between two of the sampled points, say a and b, the formula is:

      est = f(a) + (f(b) - f(a)) * (x-a) / (b-a)

EXAMPLE OF OUTPUT:

 Enter an FPA value for x: 5.0
 Found x between points 5 and 6. Values are (4, 0.421) and (6, 0.573).
 Estimated CoL: 0.497

 Enter an FPA value for x: 2.0
 x found to be equal to point 4. Its value is (2, 0.264).
 Estimated CoL: 0.264

 Enter an FPA value for x: 500
 whoa! Sorry, no can do! That's beyond my jurisdiction.