I need some help with a line of code I just can't figure out how to deal with. I need to write a single line function that accepts 4 parameters m, b, x1, and xn that returns the definite integral of mx + b over the interval x1<= x <= xn. The code that I copied here isn't completely finished but I just wanted to write a rough draft, I just have no clue how to write the integration function. Any help would be appreciated greatly.
* Statement: Find the least squares line for the data in mp5.inp and
* integrate it from the first x value to the last x value.
* Specifications:
* Input - a sequence of (x, y) values from a sequential file
* Invokes- linreg to determine linear regression line and correlation coeff
* - integrate to determine the area under the curve
* Output - to a sequential file
* - the least squares line y = m*x + b
* - the correlation coefficient
* - the integral of m*x+b over the first x to the last
************************************************************************/
#include <fstream>
#include <iomanip>
#include <cmath>
using namespace std;
// prototype of functions linreg & integrate
int main()
{
// numeric variable declarations
double m, b, firstx, lastx, r;
// file variable declarations and initialization
ifstream fin;
ofstream fout;
// 5) disconnect from files
fin.close();
fout.close();
}
/*Function integrate
*
*receives - Slope m of least squares line
* - y intercept of least squares line
* - limits of integration
*returns - the antiderivative m*x^2/2 + b*x evaluated at x
*************************************************************************/
// Define function integrate below
integrate (double, double, double, double);
// 1) integrate a linear function
//NEED HELP HERE
/*Function linreg
*
*receives - input file object fin
*returns - Slope m of least squares line
* - y Intercept m of least squares line
* - Correlation coefficient r of least squares line
*************************************************************************/
// Define function linreg below
Integrate the function mx + b by hand to equal I for example.
Hard code the integral in terms of x in your function and return the value of I(x2) - I(x1)