Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Introduction In this assignment you will write a small C program to read the coefficients of a third degree equation, and use a numerical
Introduction In this assignment you will write a small C program to read the coefficients of a third degree equation, and use a numerical integration method for calculating a numerical value of a definite integral in the range x= a to x=b using N intervals. The C program should be submitted as a standard C source code file. You can submit your files separately or zipped together into one file. Please note that the computer program should comply with the commenting and formatting rules as has been done in class. For example, there should be a header for the whole program that gives the author's name, class name, date, and description. End braces should be commented, and there are alignment and indenting requirements as discussed. Please ask if you have any questions. Program Background: A third-degree polynomial equation is represented as f(x) = mx + nx + px + q. Where m, n, p and q are real values. f(x) = mx + nx + px + q; vm, n, p, q ER Numerical integration consists of finding numerical approximation for the value S in Figure 1. To find the value of S, you will implement and compare two different solutions: f(x) S b x Figure 1: Numerical Integration 1) Midpoint rule: Also known as the rectangle rule; is used to compute an approximation to a definite integral. This is achieved by finding the area of rectangles whose height is determined by the value of a function. The interval [a,b] over which the function is to be integrated is divided into N equal subintervals of length Ax = (b-a)/N. The approximation to the integral is then calculated by : [F(x) f(a + -* Ax) 2k-1 2 f(x) dx Ax * k=1 2) Trapezoidal rule: Similar to 1), but in this case the height of the rectangle, requires to evaluate f(x) at two different points. The general formula: Ax [ f(x) dx = = = * (f(x) + 2 + f (x) + 2 * (x) + ... + 2 + (xx-1) + (x)) Where Ax is the same as in 1), and x = a + k * Ax; for k=0 to N; Assignment: Your first program is a simple mathematical calculation. You will write a C program that shows a menu to get 4 real values from the user, namely m, n, p and q(20 points); once these values are provided, the user can enter the integration range and intervals(i.e. the values for a, b and M) (10 points). A third option will calculate the value of S, using methods 1 (midpoint) (20 points) and 2(trapezoidal) (20 points) explained above and display the results as well as the difference between the value of Si obtained with method 1, and the value of S obtained with method 2. A function MUST be written for each method (midpoint and trapezoidal). Your program should prompt the user for these values (coefficients, range and interval), accept input from the keyboard, and then print out the result on the screen. You can use a menu with the following options: a) Enter new coefficients (m, n, p and q) b) Enter the value for a, b and N c) Calculate the integral from a to b d) Exit ii). Include a report in a Word file that shows the results for the following values: i). Coefficients (-1, 4, -5, 2) and range (0,5) with N = 100 (2 points) Coefficients (-1, 4, -5, 2) and range (0,5) with N= 1000 (3 points) Coefficients (1, 5, 7, 2) and range (-2.5,1) with N= 1000 (2 points) iv). Coefficients (1, 5, 7, 2) and range (-2.5,1) with N = 100000 (3 points) v). Coefficients (1, 0, -1, 8) and range (-1,1) with N= 100000 (5 points) iii). vi). Coefficients (1/4, 3/4, -6/4, -2) and range (-4,2) with N= 100000 (5 points) Add your observations (10 points): i.e. what happens with v) and vi)? You can use the function pow(), found in , to calculate the powers of x. Topics covered: Expression evaluation, operators, flow control statements (loops, switch-case, if- else, etc.) and functions.
Step by Step Solution
★★★★★
3.47 Rating (163 Votes )
There are 3 Steps involved in it
Step: 1
Note I have used step size as 1000 for integration so the error is less for me if you want ...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