Arrays

Arrays and interpolation

Page 1 of 1

3 Replies - 7223 Views - Last Post: 30 March 2008 - 04:30 PM Rate Topic: -----

#1 jrc43   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 29-March 08

Arrays

Posted 29 March 2008 - 09:16 PM

Here is the assignment:

The input file tunnel.txt contains 17 wind-tunnel measurement pairs which consist of a flight-path angle (in degrees) and its corresponding coefficient of lift on each line in the file. The flight-path angles are sorted in ascending order. Write a program that reads the wind-tunnel data into an appropriate array(s), prints a message showing the range of angles that are covered in the data file, and then allows the user to enter a flight-path angle. If the angle is within the bounds of the data set, the program should then use linear interpolation to compute the corresponding coefficient of lift and display it on the screen. If the user’s input is outside the range, the program should print an error message indicating so. The program should keep asking the user to enter flight-path values as long as the user desires.

I have attached what I have so far. What I am having a problem figuring out is how i'm suppose to use the interpolation equation.

f(B ) = f(A) + [(B-A)/(C-A)] * [f( C)-f(A)]

I don't know how to get f(a) or f(c ). I attached my code and I really appreciate any help recieved because this one has me stumped. Thanks


#include <iostream>
#include <fstream>
#include <cmath>

using namespace std;

int main()
{

	double flight_path_angle[17], lift[17], f_a, fl_ang;
	string filename;
	ifstream tunnel;
	
	cout << "Enter the name of the input file." << endl;
		 cin >> filename;
	
	cout << endl;
	
	tunnel.open(filename.c_str());
	
	if( tunnel.fail())
	  {
		  cout << "File could not be opened.\n";
	  }
	
	else
	{
	   for (int k=0; k<=16; k++)
	   {
		   tunnel >> flight_path_angle[k] >> lift[k];
	   }
	
		cout << "Range of flight-path angles: " << flight_path_angle[0] << " to " << flight_path_angle[16] << " degrees" << endl;
	
		cout << "Please enter the flight-path angle in degrees: ";
			cin >> fl_ang;
			
	  if (fl_ang < 21 || fl_ang > -4)
		 {
		 
	  
	  
	   
	   
	   
	
	
	}
	
	
	system("PAUSE");
	return 0;
}

Attached File(s)

  • Attached File  tunnel.txt (165bytes)
    Number of downloads: 234

This post has been edited by jrc43: 29 March 2008 - 09:27 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Arrays

#2 Martyr2   User is offline

  • Programming Theoretician
  • member icon

Reputation: 5612
  • View blog
  • Posts: 14,686
  • Joined: 18-April 07

Re: Arrays

Posted 30 March 2008 - 12:52 PM

Hi JRC43,

F(a) and F© are going to be your two flight coefficients for the values on either side of the entered flight angle from the user. Taking a look at your win tunnel data. If the user enters an angle of 1 degree your program (and the formula) will take the flight data for angle 0 and angle 2 and their coefficients 0.097 and 0.238 respectively and it is going to be plugged in for F(a) and F©..

So....

f(b) = .097 + ((1 - 0) / (2-0)) * (.238 - .097) 



After solving you should come up with a value .1675 which is the new life coefficient for the flight angle of 1 degree.

Now keep in mind that this is an interpolation and thus is an estimate value based on a set of values that form a curve. These coefficients are approximations to points that lie on that curve.

I compared some of these values to values listed in the higher angles and they are off by something like a few hundreds at most but in line with the values. So don't expect them to be right dead on the money. Ask your teacher if the values in the files are going to be exactly lined up with your calculations. I bet they might be slightly off.

So that should get you moving in the right direction with this project. Hope this is what you were looking for. Enjoy!

:)
Was This Post Helpful? 0
  • +
  • -

#3 jrc43   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 29-March 08

Re: Arrays

Posted 30 March 2008 - 01:17 PM

Thanks! I understand that part now. How do I represent f_a and f_c in that problem. I would have to access that part of the array, right? But, how would the users input reflect the part of the array? For example, if the user input 3.5 for the flight angle, how would i access the part of the array for the lift of 4 and 3? I really appreciate the help.
Was This Post Helpful? 0
  • +
  • -

#4 Martyr2   User is offline

  • Programming Theoretician
  • member icon

Reputation: 5612
  • View blog
  • Posts: 14,686
  • Joined: 18-April 07

Re: Arrays

Posted 30 March 2008 - 04:30 PM

Well first you are going to read in the angle from the user and determine if it is in the range of angles from -4 to 21, yes it is. Notice the values of these angles are in sorted order. More on this in a second.

The best way to implement this would two arrays that lie in parallel. One array contains the angles while its corresponding array contains the lift coefficients.

Now since they are sorted, it is easy to loop through and find values. Loop through the angles array. If the value is found, you can immediately stop (as it says in your directions). Otherwise you are going to run into a value in the array which is bigger than the user entered. In our case it will go -4, -2, 0, 2, 4 and realize that 4 is bigger than 3.5. In your array the value 4 should correspond to array index 4 as well and the lower limit is therefore index 3. So your two coefficients will be located at coefficients[3] and coefficients[4]. Then you will have all the data you need for the equation.

// If the user entered lift coefficient 3.5 you would search and come
// to the conclusion that upper bound is index 4 and lower bound is index 3

double f_a = coefficients[3];
double f_c = coefficients[4];

int a = angles[3];
int c = angles[4];

// Angle b was entered by user
cin >> b;




I hope I am making it clear. :)

This post has been edited by Martyr2: 30 March 2008 - 04:32 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1