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

1 次查看(过去 30 天)
For example, f = 5, for 0<t<1, zero otherwise.
i tried the following code but it didn't work:
syms t
f = 10;
int(f)

采纳的回答

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
Try this:
syms t
f = 0*t + 10;
int(f);
Cheers Manuel
  3 个评论
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

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Mathematics 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by