Answer to Question #335710 in C++ for Suchperson

Question #335710

The Rectangular Rule A. The rectangular rule (also called the midpoint rule) is perhaps the simplest of the three methods for estimating an integral. i. Integrate over an interval a ≤ x ≤ b. ii. Divide this interval up into n equal subintervals of length h = (b − a)/n. iii.Approximate f in each subinterval by f(x*j ), where x*j is the midpoint of the subinterval. iv. Area of each rectangle: f(x*j)h, f(x*j)h,. . . , f(x*n)h. The approximation on the RHS becomes more accurate as more rectangles are used. In fact, You are required to: v. write pseudocode algorithm to determine the integral of a function between two specified points using the rectangular rule. vi. write C++ computer programs to determine the integral of a function between two specified points using the rectangular rule.


1
Expert's answer
2022-05-01T19:06:26-0400
#include<iostream>
#include<cmath>
#include<iomanip>

using namespace std;

double approx(double x)
{
	return (6 * pow(x, 4) - 7 * pow(x, 3)+4*x);
}

int main()
{
	double a, b;
	int n;
	cout << "Please, enter lower limit: ";
	cin >> a;
	cout << "Please, enter higher limit: ";
	cin >> b;
	cout << "Please, the number of rectangles: ";
	cin >> n;
	double s = (approx(a) + approx(b)) / 2;
	double h = (b - a) / n;
	for (int i = 1; i <= n-1; i++)
	{
		s += approx(a + i*h);
	}
	double I = h*s;
	cout << setprecision(10) << I << endl;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS