Riemann Sum is a way to approximate the area under a continuous curve. Google Ri
ID: 3544166 • Letter: R
Question
Riemann Sum is a way to approximate the area under a continuous curve. Google Riemann Sum and learn
it if you do not already know it. In this question, you are to write a function that computes, via Riemann
Sum, the integral of function f dened as follows f(x)=0.5e^(-x^2/2)
The name of the function is to be called integrateF, it takes two arguments (double low, double
high); it returns a double-typed value which is approximately equal to the integral of function f from lower
limit low to higher limit high.
Explanation / Answer
using namespace std;
#include <iostream>
#include <cmath>
double function(double n);
double quadrature(double a, double b, int n);
int main(){
double a; // left edge of interval
double b; // right edge of interval
int n; // number of "slices"
// prompt user and read in a, b, and n
// read in a, b, and n.
double areaQuad = quadrature(a,b,n); // get quadrature answer
double areaTheo = (b*b*b - a*a*a) / 3; // theoretical answer
double absErr = abs(areaQuad - areaTheo); // absolute error
double relErr = absErr / abs(areaTheo); // relative error
cout << " Area computed: " << areaQuad;
cout << " Area theoretical: " << areaTheo;
cout << " Absolute error: " << absErr;
cout << " Relative error: " << relErr;
return EXIT_SUCCESS;
}
//**************************************
double function(double x){
return x*x;
}
//**************************************
double quadrature(double a, double b, int n){
double h = (b-a)/n; // divides interval up into n equal subintervals
double sum = 0;
double
return sum;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.