Trapezoidal question set, big problems (new user)

1 view (last 30 days)
Hi all, I am very new to MATLAB and have been learning it for the past few weeks. I have a problem set where I must integrate a function y with respect to x using the trapezoidal rule in the range a to b.
The function is y=(x^3)+(2*(x^2))-x+3
I am stuck as to where to start with implementing this. I already know the trapezoidal rule but I just can't get it into MATLAB. I have also tried reading through tutorials on the MATLAB built in stuff but none of them seem to help because they usually revolve around an easy, simple function like Sin(x). None of them seem to refer to integrating a function of something with respect to something.
I also have to find the optimum interval for n which I do not understand either.
I am just wondering if anyone can point me in the right direction because I really have no idea where to start with this one.

Answers (2)

Roger Stafford
Roger Stafford on 10 Nov 2014
Edited: Roger Stafford on 10 Nov 2014
Assuming you are not allowed to use 'trapz', the algorithm for trapezoidal integration is very simple to implement in matlab. See:
http://en.wikipedia.org/wiki/Trapezoidal_rule
In deciding about the number of subintervals, n, to use, it is a matter of balancing between the inherent error in the trapezoid approximation, as opposed to the cumulative buildup due to rounding errors in the computations. You can decide that by making comparisons for different n with the known values of your integral which are easily determined using integral calculus.

Chad Greene
Chad Greene on 9 Nov 2014
Can you use the unfortunately-named cumtrapz function?
What do you mean by the optimum interval for n? What is n?

Community Treasure Hunt

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

Start Hunting!