I'm trying to write a program to calculate and output area under the curve y = 0.6x^2 + 4 to 12 decimal places.
I want the program to calculate the area using (1)upper limit method (2) lower limit method (3) the midpoint method as well as (4) the trapezoidal method.
I also want the program to calculate for three different segment values, n = 5, 50, and 500.
I understand the basics of functions, calling:
double f (double x)
{
return 0.6*pow(x,2) + 4
}
But I haven't the slightest clue how to program for all four methods mentioned above. Any help would be greatly appreciated.
// This program calculates and displays area under a curve using LL, UL, MP, and trapedzoidal methods
#include <iomanip>
#include <iostream>
#include <math.h>
usingnamespace std;
double f(double x)
{
return 0.6*pow(x,2) +5;
}
int main ( )
{
double a, b, delx, x, area;
int n;
cout << "Welcome. To begin, please enter a value for 'a' followed by a value for 'b'. \n";
cin>>a>>b;
cout << "You have entered a = " << a<<" & b = " <<b <<". Now, input an n value \n";
cin >>n;
delx = (b-a)/n;
area = (f(a)+f(b))/2;
for (int i=1;i<n;i++)
{
area += f(a+i*delx);
area = area*delx;
}
cout << "The area under the curve of f(x) = 0.6x^2 + 4 is ";
cout << setprecision(12) << area;
}