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

조회 수: 2 (최근 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
Jinquan Li
Jinquan Li 2021년 2월 23일
Thanks a lot! this works!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by