Trapezium Rule value not correct

1 view (last 30 days)
beth
beth on 30 Apr 2014
Commented: beth on 30 Apr 2014
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!!!
  3 Comments
Geoff Hayes
Geoff Hayes on 30 Apr 2014
What code is there (in ni2.m) to plot the steps? I just see code to plot the function.
beth
beth on 30 Apr 2014
I have to create an equation for the trapezium rule rather than use the trapz function. Ah I seem to have deleted the steps and stairs by accident, I had originally put stairs(x,y,'r'); steps(x,y,'r');
I typed this in after the line plot(x,y).

Sign in to comment.

Accepted Answer

the cyclist
the cyclist on 30 Apr 2014
Edited: the cyclist on 30 Apr 2014
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.
  4 Comments
beth
beth on 30 Apr 2014
thank you so much, the graph is looking a lot better. however when running the default program the value for the trapezium rule is higher than the value of the accurate result and simpsons rule result. any thoughts on why?
beth
beth on 30 Apr 2014
also wouldn't y(i) not be recognised as we haven't defined y?

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!