Trapezium Rule value not correct

1 次查看(过去 30 天)
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 个评论
Geoff Hayes
Geoff Hayes 2014-4-30
What code is there (in ni2.m) to plot the steps? I just see code to plot the function.
beth
beth 2014-4-30
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).

请先登录,再进行评论。

采纳的回答

the cyclist
the cyclist 2014-4-30
编辑:the cyclist 2014-4-30
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 个评论
beth
beth 2014-4-30
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 2014-4-30
also wouldn't y(i) not be recognised as we haven't defined y?

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by