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

2 vues (au cours des 30 derniers jours)
Jinquan Li
Jinquan Li le 23 Fév 2021
Commenté : Jinquan Li le 23 Fév 2021
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)

Réponse acceptée

Walter Roberson
Walter Roberson le 23 Fév 2021
Modifié(e) : Walter Roberson le 23 Fév 2021
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 commentaire
Jinquan Li
Jinquan Li le 23 Fév 2021
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)

Connectez-vous pour commenter.

Plus de réponses (1)

Just Manuel
Just Manuel le 23 Fév 2021
Try this:
syms t
f = 0*t + 10;
int(f);
Cheers Manuel
  3 commentaires
Just Manuel
Just Manuel le 23 Fév 2021
Modifié(e) : Just Manuel le 23 Fév 2021
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 le 23 Fév 2021
Thanks a lot! this works!

Connectez-vous pour commenter.

Catégories

En savoir plus sur Numerical Integration and Differentiation dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by