OK so the entire program is below:
Code:
#include <stdio.h>
//#include <math.h>
const float dx = 0.125; //change in x displacement, i.e measurment interval.
float v[11], U;//My global floating varables
int i,n;//My global integers, counts for loops etc
int collectdata() //retrieves data from text file
{
int i;
FILE *fp=NULL; //create a pointer, fp to point at the file the data points are stored at
fp = fopen("data.txt", "r"); //open the data file from the saved location and read from it
for (i=0; i<11; i++) //for loop scans each data point from the file and stores it in the velocity array, v.
{
fscanf (fp, "%f\n", &v[i]); //scans for integers in data file
}
fclose(fp); //close data file
}
int trapezium()//this part copes with calculating each value of f(x), i.e f(x1), f(x2) etc and then outputting the estimated area under the graph
{
float fx[11],y,a,b;
//a and b are variables that help towards the final value for y, y being the displacement thickness
//fx is the function value, in this case the displacement thickness
for(i=0;i<11;i++)
{
fx[i] = ((1 - v[i])/U);
}
for (n=1;n<10;n++)
{
a = a +fx[n]; //a is a section of the trapezium rule
//printf("a = %5.2f\n", a);
}
b= fx[0] + fx[10]; //more trapezium rule
y = (dx/2) * (b + (2*a)); // final trapezium rule
printf("y = %5.2f", y); //print the estimated area under the graph
}
int main()
{
collectdata();//runt he function to collect the data from the text file
for(i=0;i<11;i++)//for loop to print all data points to the screen
{
printf("v%d= %5.2f\n", i+1, v[i]); //print the speeds retireved from the file
}
U = v[10]; //set U to the free stream veolcity - the greatest recorded speed above the wing
trapezium(); // run the function to calculate the displacement thickness
return 0;
}
Like it is it outputs an answer y=-0.72
But it prints all the values for the speed above, from the line
printf("v%d= %5.2f\n", i+1, v[i]); //print the speeds retireved from the file in the main function,
if you remove that line you get y=#R