How to integrate the following function(using "int" command)

How to integrate the following function(using "int" command)
f(x)=
x if 0 < x < 2
x^2 if 2 <= x <= 10

回答 (2 件)

Shashank Prasanna
Shashank Prasanna 2013 年 1 月 21 日

0 投票

Why don't you set up two different integration problems:
f1 = quad(@(x)x,0,2)
f2 = quad(@(x)x^2,2,10)
If you are concerned about boundary problems, you could always perturb the values a bit.

4 件のコメント

Shashank Prasanna
Shashank Prasanna 2013 年 1 月 21 日
If you are using symbolic toolbox then:
numeric::int(x, x = 0..2)
numeric::int(x^2, x = 2..10)
Walter Roberson
Walter Roberson 2013 年 1 月 21 日
Note: numeric::int is a MuPAD function that has no MATLAB interface. You would need to use feval() or evalin() to access it.
Shashank Prasanna
Shashank Prasanna 2013 年 1 月 21 日
Good point walter, I assumed Abhishek was using MuPAD from his question about 'int', hence I added the second comment. Abhisek, you can launch mupad as below if you want to work in that environment:
>> mupad
or use evalin in MATLAB as below.
>> evalin(symengine,'numeric::int(x^2, x = 2..10)')
hth
Walter Roberson
Walter Roberson 2013 年 1 月 21 日
int() is one of the MuPAD routines that does have a MATLAB interface.

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

Walter Roberson
Walter Roberson 2013 年 1 月 21 日

0 投票

Within MuPAD you can use piecewise to define the function, and then int() it. Note that piecewise is a MuPAD function that has not MATLAB interface. You would need to use feval() or evalin() to access it.

タグ

質問済み:

2013 年 1 月 21 日

Community Treasure Hunt

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

Start Hunting!

Translated by