Program Does Numerical Integration For Data Sets Located in an Input File. The Code has to be All C language no C++

Paste Bin Link to The Full Code
http://pastebin.com/NRVDqxdj

Could Someone Help Me With This:

Calculate the total area under the curve for this data set, starting with an h value of 0.1 and then continuing with h = 0.01, 0.001, etc. [b]until the latest two calculations are within 0.0005 of each other, or h becomes 0.00001.[/b] For each of these calculations report the h value, the value of N and the area calculated.

The Section in Bold is The Bit Where im Confused on How to Do It

Another Problem Im Having is Creating My Own Functions:
These Calculations I Want in Functions But Can't Figure It Out

``````for ( Height = 0.1; Height >= 0.00001; Height = Height * 0.1 ){

N = (X_Final - X_Initial) / ( Height ) + ( 0.5 );

X_a = X_Initial;

Area_Total = 0;

for ( int i = 0 ; i < N ; i++){

X_b = X_a + Height;

Area_i = Height * (abs(X_a*X_a + B*X_a + C + D/X_a) + abs(X_b*X_b + B*X_b + C + D/X_b)) * 0.5;

Area_Total = Area_i + Area_Total;

X_a = X_b;

}
``````

Also if You See anything Else That Needs Fixing Can You Please Post it
- Such as The Formatting

## All 3 Replies

Format for creating user defined function is

`````` return_type function_name ( arguments )
{
//function body

}
``````

Also in the code posted, one ' } ' is missing.

You are calculating the area under curve. Do the calculations inside a functionand return the answer.

For example :

``````double CalcArea( X_final, X_Initial, // other arguments )
{
double Area_Total = 0 ;

// calculate the area here and store it in a variable say Area_Total

return Area_Total ;
}
``````

Sorry But i Don't Understand =( and where abouts is the "}" missing

Also Need Help On

Calculate the total area under the curve for this data set, starting with an h value of 0.1 and then continuing with h = 0.01, 0.001, etc. until the latest two calculations are within 0.0005 of each other, or h becomes 0.00001. For each of these calculations report the h value, the value of N and the area calculated

How Would I Achieve This?

would have to be like

``````Area_Total_Check = Area_Total (Previous Example) - Area_Total (Newest Value);
if ( Area_Total_Check = 0.0005 || h = 0.00001 ){
input_status = fscanf(inp, "%d %d %d %lf %lf", &B, &C, &D, &X_Initial, &X_Final);
}
else
{
/* Continue to Calculate till it does that */
``````
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.