MATLAB: Trapezium Rule value not correct

errornumerical integrationplotrectangle rulesimpsons ruletrapezium rule

Hello, I posted on here earlier about a problem with my function but I have managed to fix that problem. However the value for my trapezium rule is wrong and I was wondering what I had done wrong? Also my graph won't create the stairs and steps that I have created, the area underneath the graph is just filled in red instead of creating rectangles unless there is a better way to plot the rectangle rule? I have attached my code to this question, help would be fantastic as the code is due in for hand in on friday and I am very stuck!!!

Best Answer

For your default program, the exact value is 2500 and the trapezium value is about 2313. That does not seem wrong to me, for 50 bins. If I use 5000 bins, it gets about 2498. Again, seems fine to me.
Regarding plotting ... you seem to only be plotting the exact value curve. So, it is impossible to provide any advice on why your code may be wrong.
If you want to plot the individual rectangles, I would suggest using the bar() function.
Related Question