Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In C programing with comments and OUTPUT please Introduction In this assignment you will write a small C program to read the coefficients of a
In C programing
with comments and OUTPUT please
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 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; m, n, p, q ER Numerical integration consists of finding numerical approximation for the value S in Figure 1. AY To find the value of S, you will implement and compare two different solutions: f(x) 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 S 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 : Figure 1: Numerical Integration 2k - 1 1x Ax) 2 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: a N ' dx = ax = { fca + SFWdx = * * (9686) +2+ f(x) +2+ f(x)) + - +2+ f(xn-1) + f(x2) Where Ar is the same as in 1), and xk = 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 N) (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 S, obtained with method 1, and the value of S2 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 the value of S, obtained with method 1, and the value of S2 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 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) ii). Coefficients (-1,4,-5, 2) and range (0,5) with N = 1000 (3 points) iii). 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) 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)? Please enter the values for each menu item: Please Enter A to enter new coefficients (m, n, p and q) Please Enter B to enter the value for a, b and N Please Enter C to Calculate the integral from a to b Please Enter D to exit Enter a choice between A to D or a to d: c Enter new coefficients (m, n, p and q): -1 4-50 Enter the value for a, b and N: 0 5 10000 Calculating the integral from a to b: The value calculated using midpoint is - 52.070834 The value calculated using trapezoidal is -52.095834 The difference between both is 0.025000 Please enter the values for each menu item: Please Enter A to enter new coefficients (m, n, p and q) Please Enter B to enter the value for a, b and N Please Enter C to Calculate the integral from a to b Please Enter D to exit Enter a choice between A to D or a tod: d Please enter the values for each menu item: Please Enter A to enter new coefficients (m, n, p and q) Please Enter B to enter the value for a, b and N Please Enter C to Calculate the integral from a to b Please Enter D to exit Enter a choice between A to D or a to dig Enter a choice between A to D or a tod: & Enter a choice between A to D or a to d: 9 Enter a choice between A to D or a tod:( Enter a choice between A to D or a to d: a Enter new coefficients (m, n, p and g): -1 4-5 2 Enter the value for a, b and N: 0 5 10000 Calculating the integral from a to b: The value calculated using midpoint is -42.070834 The value calculated using trapezoidal is -42.095334 The difference between both is 0.024500 Please enter the values for each menu item: Please Enter A to enter new coefficients (m, n, p and q) Please Enter B to enter the value for a, b and N Please Enter C to Calculate the integral from a to b Please Enter D to exitStep 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