| bruntmjust (49) | |
|
These are the variables: n = number of rectangles and/or trapezoids a = beginning x value b = ending x value h = width of each rectangle/trapezoid, (b-a)/n f(x) = height of rectangle (f(x1)+f(x2))/2 = height of trapezoid Area = width*height In order to finish my integration problem I really need to see how this example works: Choose a function (1, 2, 3, 4, 5, other(quit)): 1 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 5x4 + 3x3 – 10x + 2 between 1 and 2 is 29.25 Can someone show me how to do this in code please? Once I see this I will be able to do the 4 other programs. Please help. I need to see mainly how to get the function to work with the user input. | |
|
Last edited on
|
|
| aperio (15) | |
| Please post what you have written so far and then we can proceed from there. | |
|
|
|
| bruntmjust (49) | |||
Okay, this code compiles and I am just messing with things right now and it doesn't work.
The whole assignment detail I am doing is in another post of mine. | |||
|
|
|||
| bruntmjust (49) | |
| If anyone can help me get this program running the way it should please let me know. | |
|
|
|
| aperio (15) | |||
|
Ok. I have the first part for you. (I'm sure there is a much more efficient way of writing this, but this is what I had time for). This will calculate the total area under the curve of f(x) = sqrt(x-1). This code has been validated with the following parameters: Start: 1 End: 6 Number of trapezoids: 5 area = 7.264 Please read the comments in the code to understand what each line is doing. For detailed information about how this function is calculated (which may help understand how the program works) look here: http://www.youtube.com/watch?v=1p0NHR5w0Lc
| |||
|
Last edited on
|
|||