- **C++**
(*http://www.go4expert.com/forums/cpp/*)

- - **Area under a curve**
(*http://www.go4expert.com/forums/curve-t27946/*)

Area under a curveHey im working on a program that evaluates the area under a curve. The curves that will be asked to evaluate are polynomials of the 4th, 3rd, and 2nd order:
4th order: y(x) = ax4 + bx3 + cx2 + dx + e 3rd order: y(x) = ax3 + bx2 + cx + d 2nd order: y(x) = ax2 + bx + c need to have the user specify whether they want to use a 4th, 3rd, or 2nd order polynomial. The user will then be prompted to specify the coefficients (a, b, c, etc. ) for their equation. This will be the equation used in the calculations. i dont know were to really start and looking for advice and some help with the math because calculus is not my strong point. |

Re: Area under a curveThe differential of ax^n is anx^(n-1) so that should be fairly easy to calculate. Typically you would want to calculate the area under a curve between two fixed points on the x-axis so you would need to input those as well. Then (using 4-th order as an example) you evaluate 4ax^3+3bx^2+2cx+d twice for the two x-values then subtract one from the other. This is not at all difficult in C and the program does not need to perform the differentiation.
By the way, you won't need to enter the last term (e for the 4th order) as this disappears when the equation is differentiated. As for where to start, well, you've been given this already. 1. I need to have the user specify whether they want to use a 4th, 3rd, or 2nd order polynomial. OK, so you need to display something, and input something. You've probably already met cout and cin by now. 2. The user will then be prompted to specify the coefficients (a, b, c, etc. ) for their equation. More display and input. Hint: use a loop and an array for this; it will be easier. If you want to use a fixed size array (e.g. double coeff[20]; ) then you will need to check the user doesn't enter too big a number in step 1. 3. This will be the equation used in the calculations. You will also need to get the x1 and x2 values, so that's more display and input. So you already know if this is a 4th, 3rd etc. So you know the power associated with coeff[0]: it will be 4 for a 4th. So as I said above, you now need to evaluate R1=4*coeff[0]*x1^3 and so on for the rest of the terms, then repeat for x2, then the result (if x1<x2) is R2-R1. Again this will be easier with a loop as you won't know until runtime what the order is. Take it a step at a time, frequently compile and test, keep a cool head and you'll have this one cracked in no time! |

All times are GMT +5.5. The time now is 21:58. |