A couple of suggestions: 1) steps should be an unsigned int, not a float, and obviously you need to return an error if steps == 0
2) It's going to be more useful to provide an interval to integrate over rather than integrate from 0 to x1
3) You redundantly evaluate the beginning function value of each step after the first more than once, try calculating F(0.0f) outside of a do... while loop and use the value at F(xn+stepsize) as the next loop value of F(xn)
4) Doesn't look like it copes correctly if x1 < 0, needs to negate the answer, need to do this if you use an interval and fStart > fEnd
5) Floating point error means repeatedly adding stepsize to xn may not give you x1 as the endpoint, you should calculate it by linearly interpolating from 0 to x1 instead.
EDIT: Keep getting stupid format tags instead of newlines in my posts?
Show differencesHistory of post edits
#1Paradigm Shifter
Posted 28 December 2012 - 06:24 AM
A couple of suggestions:<br /><br />1) steps should be an unsigned int, not a float, and obviously you need to return an error if steps == 0<br />2) It's going to be more useful to provide an interval to integrate over rather than integrate from 0 to x1<br />3) You redundantly evaluate the beginning function value of each step after the first more than once, try calculating F(0.0f) outside of a do... while loop and use the value at F(xn+stepsize) as the next loop value of F(xn)<br />4) Doesn't look like it copes correctly if x1 < 0, needs to negate the answer, need to do this if you use an interval and fStart > fEnd<br />5) Floating point error means repeatedly adding stepsize to xn may not give you x1 as the endpoint, you should calculate it by linearly interpolating from 0 to x1 instead.