views:

81

answers:

1
+1  Q: 

help with array

You will write a program that evaluates the integral of sin(x) using the left-hand rectangle rule with 2000 subintervals, over 10 intervals. The intervals to test are [0, 1), [1, 2), …, [8, 9), [9, 10). You will declare an array of type double that can hold 10 elements, and you will use this array to hold all 10 results you get from evaluating each interval.

I am in testing my code, what should be the output? For example, [0, 1)? Any idea?

Thanks.

+2  A: 

In case of a sin function you should be able to figure it out. For more complicated cases use this tool:

http://calc.matthen.com/

http://integrals.wolfram.com/index.jsp

Hamish Grubijan
Thank you Hamish for your help. I think I got verification from some other people too. So my classmates were all wrong with the area.Thanks. I just need to confirm on the output. even if i have perfect codes, only knowing the real solutions can verify the code. Thanks
JohnWong
Haha! The brutal reality ... do not mess with machines, says Kasparov.
Hamish Grubijan
@JohnWong: Actually, a numerical integration algorithm won't return the very exact answer but for some trivial cases that don't require numerical integration algorithms anyway. Given bad input (for example, bad intervals), numerical algorithms can return bogus answers.
Eduardo León
@ edurado, yes. i noticed that my answers were off by 0.0001 - 0.0002 but it was totally acceptable as you mention. thanks bro
JohnWong