numerical integration __ integral limits being variables

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

 採用された回答

Roger Stafford
Roger Stafford 2015 年 4 月 5 日

1 投票

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

その他の回答 (1 件)

Star Strider
Star Strider 2015 年 4 月 5 日

1 投票

If you are numerically integrating functions, use integral (or quad and its friends if you don’t have integral). You will obviously have to define what value ‘x’ is to do a numerical integration.
If you want to do a symbolic integration (and your function is integrable), use the Symbolic Math Toolbox int function.

3 件のコメント

Meva
Meva 2015 年 4 月 5 日
I have used
u13B = cumtrapz(x, function of x)
Is it true to use ? Many thanks
Star Strider
Star Strider 2015 年 4 月 5 日
You can use cumtrapz with data returned by your function, but not with your function itself. If you want to use a function, you have to use integral or quad, as I wrote before.
Meva
Meva 2015 年 4 月 5 日
編集済み: Meva 2015 年 4 月 5 日
what do you mean by that Can you explain more please?
I have used like:
x=linspace(0,1,0.01)
cumtrapz(x, 4*(x-0.5))
Can't I use it? It is supposed to be
int_0^x 4*(x-0.5) dx

サインインしてコメントする。

カテゴリ

質問済み:

2015 年 4 月 5 日

編集済み:

2015 年 4 月 5 日

Community Treasure Hunt

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

Start Hunting!

Translated by