Ask Engineering Mathematics Expert

Assignment - Repetition and Decomposition/Functions

Problem Statement:

Write a program, my_math.cpp, that defines 5 mathematical function and calculates the summation or integration of that function. You are creating your own library of commonly used mathematical functions and analyzing the different methods, rectangle vs. trapezoid methods, for solving integration problems to gain experience writing a short program, which uses selection, repetition, and functions/procedures.

Your program should define these 5 functions:

f1(x) = 2x5 + x3 - 10x + 2 f2(x) = 6x2 - x + 10

f3(x) = 5x + 3 f4(x) = 2x3 + 120

f5(x) = 2x2

Summation Function Explanation:

We will use the functions specified above, where x = a to b.

bΣx=af5(x)

- The summation needs a and b values for the beginning and ending values for x.
- Calculate the summation of the function, f5(x)=2x2, with a user specified a and b value
- Return the sum.

Integration Functions Explanation:

Your program should determine the area under the functions specified above. You will calculate the area under a curve using the rectangle and trapezoid method. Therefore, you need integrate_rectangle() and integrate_trapezoid() functions. Don't freak out!!! Programming integration into the computer doesn't consist of calculus. It is simple math, and these two methods only require summing the area of a certain number of rectangles or trapezoids under a specific curve, f(x).

For Example, if your f(x) = 2x:

310_Figure.jpg

Basic Numerical Methods (Rectangle vs. Trapezoid):

2138_Figure1.jpg

n = number of rectangles and/or trapezoids

a = beginning x value

b = boundary for rectangles

width = width of each rectangle/trapezoid, (b-a)/n

f(x) = height of rectangle

(f(x1)+f(x2))/2 = height of trapezoid Area = width * height

The functions are bounded by any interval on the x-axis, including both positive and negative values!!!.

You can check your answers to these functions using

http://www.wolframalpha.com/widgets/view.jsp?id=8ab70731b1553f17c11a3bbc87e0b605

Here is an example run of your my_math.cpp program:

Choose a function (1, 2, 3, 4, 5, other(quit)): 5

Which operation do you want (summation(1) or integration(2)): 2

Would you like to calculate the area using the rectangle, trapezoid, or both (1, 2, 3): 2

How many trapezoids do you want? 1000 Please select a starting point, a = 1 Please select an ending point, b = 2

The area under 2x2 between 1 and 2 is 4.667

Program Input:
- Mathematical operation to perform
- Starting and ending points for the area or summation
- Function to calculate the area or summation, i.e. f1, f2, f3, f4, f5
- Function/Procedure(s) for calculating the area, i.e. rect, trap, both
- Number of rectangles and/or trapezoids to use

Program Output:
- The function being evaluated
- Starting and ending points for the integral or summation
- For integration: Number of rectangles and/or trapezoids used
- The area or summation calculated by the method(s)

Program Description in more detail:
Your program needs to adhere to the following guidelines:

- If the user chooses to see the area calculated by both methods, each method should receive their own number of rectangles or trapezoids as input and return the value from the calculation.

- Your program should continue running until the user no longer wants to perform more calculations.

- You should use procedural decomposition and have functions for f1(x), f2(x), f3(x), f4(x), and f5(x), as well as functions for calculating the summation and area using the rectangle vs. trapezoid method.

Program Style/Comments
In your implementation, make sure that you include a program header in your program, in addition to proper indentation/spacing and other comments! Below is an example header to include. Make sure you review the style guidelines for this class, and begin trying to follow them, i.e. don't align everything on the left or put everything on one line! http://classes.engr.oregonstate.edu/eecs/fall2015/cs161-001/161_style_guideline.pdf

/******************************************************
** Program: my_math.cpp
** Author: Your Name
** Date: 10/20/2015
** Description:
** Input:
** Output:
******************************************************/

Testing

Report any checking/self-reflection you did while solving the problem. For instance, how did you make sense of the output from the implementation? This includes things such as using a calculator to make sure the output is correct, testing to make sure your code executes correctly and behaves the way you expect under specific circumstances, using external sources of information such as the internet to make sense of the results, etc. In addition, you will provide us a test plan!

You will be graded on how thorough your test plan is. Make sure you think about input you hope works and input that won't work. Your program doesn't have to handle input that doesn't work!!!

Engineering Mathematics, Engineering

  • Category:- Engineering Mathematics
  • Reference No.:- M91981628

Have any Question?


Related Questions in Engineering Mathematics

Q undirected vs directed connectivitya prove that in any

Q: Undirected vs. directed connectivity. (a) Prove that in any connected undirected graph G = (V, E) there is a vertex v ? V whose removal leaves G connected. (Hint: Consider the DFS search tree for G.) (b) Give an examp ...

All these questions should be answered in matlab 1 generate

All these questions should be answered in MATLAB !!! 1. Generate a set of 3 random patterns of dimension 12 where each value is +1 or -1.(3 random 12*12 matrix) 2. Create a 12-unit Hopfield network (a 12x12 matrix) from ...

I have these questions for a homework assignment and have

I have these questions for a homework assignment and have to show work. This works with MIPS coding language and is the class Introduction to Computer Architecture. 1. Find the 2's complement representation (in 32-bit he ...

Question 1 - many spas many componentsconsider 4 types of

Question 1 - Many spas, many components Consider 4 types of spa tub: Aqua-Spa (or FirstSpa, or P1), Hydro-Lux (or SecondSpa, or P2), ThirdSpa (or P3) and FourthSpa (or P4), with the production of products P1, ..., P4 in ...

Analytical methods for engineers assignment - calculusthis

ANALYTICAL METHODS FOR ENGINEERS ASSIGNMENT - CALCULUS This assignment assesses Outcome - Analyse and model engineering situations and solve problems using calculus. Questions - Q1. Differentiate the following functions ...

Clculus assignment -q1 find the total differential of w

CALCULUS ASSIGNMENT - Q1. Find the total differential of w = x 3 yz + xy + z + 3 at (x, y, z) = (1, 2, 3). Q2. Find the value of the double integral ∫∫ R (6x + 2y 2 )dA where R = {(x, y)| - 2 ≤ y ≤ 1, y 2 ≤ x ≤ 2 - y. Q3 ...

Numerical analysis assignment -q1 define the following

Numerical Analysis Assignment - Q1. Define the following terms: (i) Truncation error (ii) Round-off error Q2. Show that if f(x) = logx, then the condition number, c(x) = |1/logx|. Hence show that log x is ill-conditioned ...

Question what is the signed binary sum of 1011100 and

Question : What is the signed binary sum of 1011100 and 1110101 in decimal? Show all of your work. What is the hexadecimal sum of 9A88 and 4AF6 in hexadecimal and decimal? Show all of your work.

Question a signal starts at point x as it travels to point

Question : A signal starts at point X. As it travels to point Y, it loses 8 dB. At point Y, the signal is boosted by 10 bB. As the signal travels to point Z, it loses 7 dB. The dB strength of the signal at point Z is -5 ...

Show all your work not just the answerswhen you multiply 21

(SHOW ALL YOUR WORK, not just the answers) When you multiply: 21 x 68 you most likely do: 8x1 + 8x20 + 60x1 + 60x20 = 1, 428 So, there are 4 multiplications and then 3 additions. How long would it take a computer to do t ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As