WRITE A C++ PROGRAM TO IMPLEMENT THE MID POINT RULE NUMERICAL APPROXIMATION

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

WRITE A C++ PROGRAM TO IMPLEMENT THE MID POINT RULE NUMERICAL APPROXIMATION 

**Midpoint Rule**

If we consider the case where \(x_i^* \) is chosen to be the midpoint \(\bar{x_i} \) of the subinterval \([x_{i-1}, x_i]\). Then we have

\[
\int_{a}^{b} f(x) \, dx \approx M_n = \Delta x [f(\bar{x_1}) + f(\bar{x_2}) + \cdots + f(\bar{x_n})], \text{ where } \Delta x = \frac{b-a}{n} \text{ and } \bar{x_i} = \frac{1}{2} (x_{i-1} + x_i)
\]

As shown in the figure below

**Diagram Description:**  
The diagram depicts a graph of a function being approximated over the interval [a, b] using the Midpoint Rule. The x-axis is marked with intervals \([x_1, x_2, x_3, x_4]\), each rectangle’s height is determined by the value of the function \(f\) at the midpoints \(\bar{x_1}, \bar{x_2}, \bar{x_3}, \bar{x_4}\). The function is visually represented by the curve, while the rectangles provide a visual of the Midpoint approximation.

**The following algorithm uses the Midpoint Rule on \(n\) subintervals to approximate \(I = \int_{a}^{b} f(x) \, dx \):**

- **INPUT** endpoints \(a, b\); positive integer \(n\).
- **OUTPUT** approximate solution \(XI\) to \(I\).

1. **Step 1** Set \(h = \frac{b-a}{n}\).

2. **Step 2** Set \(XI = 0\); \(Xbar = a + \frac{h}{2}\).

   - **Step 3** For \(i = 1, 2, \cdots n\) do Steps 4 to 6.
     - **Step 4** Set \(XI = XI + f(Xbar)\)
     - **Step 5** Set \(i = i + 1\)
     - **Step 6** Set \(Xbar = Xbar + h\)

3. **Step 7** \(XI = XI \ast h\).
Transcribed Image Text:**Midpoint Rule** If we consider the case where \(x_i^* \) is chosen to be the midpoint \(\bar{x_i} \) of the subinterval \([x_{i-1}, x_i]\). Then we have \[ \int_{a}^{b} f(x) \, dx \approx M_n = \Delta x [f(\bar{x_1}) + f(\bar{x_2}) + \cdots + f(\bar{x_n})], \text{ where } \Delta x = \frac{b-a}{n} \text{ and } \bar{x_i} = \frac{1}{2} (x_{i-1} + x_i) \] As shown in the figure below **Diagram Description:** The diagram depicts a graph of a function being approximated over the interval [a, b] using the Midpoint Rule. The x-axis is marked with intervals \([x_1, x_2, x_3, x_4]\), each rectangle’s height is determined by the value of the function \(f\) at the midpoints \(\bar{x_1}, \bar{x_2}, \bar{x_3}, \bar{x_4}\). The function is visually represented by the curve, while the rectangles provide a visual of the Midpoint approximation. **The following algorithm uses the Midpoint Rule on \(n\) subintervals to approximate \(I = \int_{a}^{b} f(x) \, dx \):** - **INPUT** endpoints \(a, b\); positive integer \(n\). - **OUTPUT** approximate solution \(XI\) to \(I\). 1. **Step 1** Set \(h = \frac{b-a}{n}\). 2. **Step 2** Set \(XI = 0\); \(Xbar = a + \frac{h}{2}\). - **Step 3** For \(i = 1, 2, \cdots n\) do Steps 4 to 6. - **Step 4** Set \(XI = XI + f(Xbar)\) - **Step 5** Set \(i = i + 1\) - **Step 6** Set \(Xbar = Xbar + h\) 3. **Step 7** \(XI = XI \ast h\).
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Algebraic Expressions
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education