Question
Description The area under a curve can be approximated by breaking the curve into small sections of equal width. A particular section is determined by
Description The area under a curve can be approximated by breaking the curve into small sections of equal width. A particular section is determined by its left x-coordinate and right x-coordinate. Each section has the area underneath it computed using the area formula for a trapezoid: area = width * (left_height + right_height)/2, where width = (right x-coordinate - left x-coordinate). As the number of sections increases (and the width of each section decreases) the approximate area converges to the actual area. For this program, the user will specify the width of each section based on the required accuracy. The left_height and right_height are determined by plugging the corresponding x-values for the current section into the function that defines the curve. In this way, integration can be approximated by arithmetic. Part 1 Given a function, a starting x-value (a), an ending x-value (b), and the number of sections (n), your program should compute the approximate area under the curve using the Trapezoid Approximation Method described above. To make your program modifiable, (allowing you to change the function that you are computing the area for) create a header file with the following #define statements in it. #define FXL (0.8*pow(x_left, 4) - 6.3*pow(x_left, 3) + 4.1) #define FXR (0.8*pow(x_right, 4) - 6.3*pow(x_right, 3) + 4.1) Note : The parentheses around the function are important! When you need to evaluate the polynomial (or any function) to obtain the left_height and right_height, simply place FXL and FXR in your source code, and the preprocessor will replace them with the function defined in your header file. You will, of course, need to #include the header file. Part 2 It is possible to approximate double integrals (and higher dimensions) using the trapezoid method. The equations of motion are often used in games and frequently need to be integrated to find the player's velocity and position. Velocity is obtained by integrating acceleration. Position is obtained by integrating velocity. Given a 1-D function for acceleration (as a function of time), your program should compute the 1-D position assuming that the velocity at time t=t0 is 0 and the position at t=t0 is 0. You will need to use a nested loop to accomplish this. In order to find the area underneath a position section, you will need the velocity at the start and end of that section to use the trapezoid method, but you don't have the function for velocity, only for acceleration. This means that you will need to use the trapezoid method with the acceleration function in order to obtain the velocity at the end of the section. #define FXL (4 + 6*tv_left) #define FXR (4 + 6*tv_right)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started