how to estimate/evaluate the integral of a constant value function?

 採用された回答

Walter Roberson
Walter Roberson 2021 年 2 月 23 日
編集済み: Walter Roberson 2021 年 2 月 23 日
syms t a b real
f = piecewise(0 < t & t < 1, 5, 0)
f = 
int(f, t, a, b)
Warning: Unable to check whether the integrand exists everywhere on the integration interval.
ans = 

1 件のコメント

Jinquan Li
Jinquan Li 2021 年 2 月 23 日
thanks. this works. Now i have another question. What if i use numerical integration? Here is what i tried:
f1 = @(t) piecewise(0<t & t<1, 10, 0);
q = integral(f1,0,1)

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

その他の回答 (1 件)

Just Manuel
Just Manuel 2021 年 2 月 23 日

0 投票

Try this:
syms t
f = 0*t + 10;
int(f);
Cheers Manuel

3 件のコメント

Jinquan Li
Jinquan Li 2021 年 2 月 23 日
Thank you! What if i use numerical integration?
Just Manuel
Just Manuel 2021 年 2 月 23 日
編集済み: Just Manuel 2021 年 2 月 23 日
you can't use piecewise in a numerical context. redefine your function as follows:
f = @(t) 5 .* (t > 0 & t < 1);
% then you can calculate numerical integral like this
integral(f, -1, 1)
Cheers
Manuel
Jinquan Li
Jinquan Li 2021 年 2 月 23 日
Thanks a lot! this works!

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

カテゴリ

Community Treasure Hunt

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

Start Hunting!

Translated by