MATLAB: Numerical integration __ integral limits being variables

numerical integration

Hello, I want to numerically integrate functions whose upper limits x, lower limits 0. Say;
int_0^x f(x) dx
Which method should I use. trapz, simpson, or omething else and which command ?
I mean can you send a simple example of doing this please? Thanks

Best Answer

There are a number of ways you can proceed. One way is to use 'int' with a variable upper limit. See:
http://www.mathworks.com/help/symbolic/int.html
If that does not succeed (which often happens) you can do numerical integration using the 'cumtrapz' function which also allows you to have a variable, though discrete, upper limit. See
http://www.mathworks.com/help/matlab/ref/cumtrapz.html
Finally, there are several functions in the File Exchange which are numerical but have higher precision. I wrote one of these. It is located at:
http://www.mathworks.com/matlabcentral/fileexchange/19152-cumulative-cubic-integration
Related Question