Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a C program that calculates an approximate value for the definite integral of a curve using each of the two methods, the rectangle rule

Write a C program that calculates an approximate value for the definite integral of a curve using each of the two methods, the rectangle rule and the trapezoidal rule.

Define these functions first:

myFunc, which calculates a single value based on the underlying function that is being integrated. It basically returns f(x) for some input value x. As an illustration, we will set myFunc to be a polynomial function f(x) = x3 - 3x2 + 2. Prototype is double myFunc(double x);

calcAreaRect, which calculates the area between two endpoints a1 and b1 using the rectangle method. This function will call myFunc. Prototype is double calcAreaRect(double a1, double b1);

calcAreaTrap, which calculates the area between two endpoints a1 and b1 using the trapezoidal method. This function will call myFunc. Prototype is double calcAreaTrap(double a1, double b1);

calcIntegral, which returns the approximation value between two end points, a and b, based on either the rectangle or trapezoidal method. calcIntegral will: (1) Divide the region between a and b into num_intervals subregions. (2) Calculate the approximate value for each sub-region according to the function calcAreaRect or calcAreaTrap. (3) Sum them all up to get the final result and return it. Prototype is double calcIntegral(int method, double a, double b, int num_intervals); // method = 1 indicates rectangle method, method = 2 indicates trapezoidal method

Follow this outline of programs logic

Ask the user which method he/she would like to use to do the integration, i.e., rectangle or trapezoid, and then to specify the endpoints. Do input validation on the method.

set num_intervals = 2

while (user has not selected to quit && num_intervals 4/4 x3 + 2x for verification

image text in transcribed

Curve of f(x) = x3 - 3x2 + 2.

Examples of Output:

image text in transcribed

image text in transcribed

feedback

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Graph Databases In Action

Authors: Dave Bechberger, Josh Perryman

1st Edition

1617296376, 978-1617296376

More Books

Students also viewed these Databases questions

Question

1. What are the peculiarities of viruses ?

Answered: 1 week ago

Question

Describe the menstrual cycle in a woman.

Answered: 1 week ago

Question

1. Who should participate and how will participants be recruited?

Answered: 1 week ago