Solving an equation with integral with one variable
Afficher commentaires plus anciens
Hi, how can I calculate the following equation involving an integral in matlab?
C + Integral_{-4}_{4} e^(x^2)*x^2 dx = 1
where -4 and 4 are the lower and upper limit, and C is the unknown constant.
Thanks!
Réponse acceptée
Plus de réponses (1)
Star Strider
le 10 Août 2017
Modifié(e) : Star Strider
le 10 Août 2017
If I understand correctly what you want to do, this works:
f = @(x) exp(x.^2) .* x.^2;
Cs = fzero(@(C) C + integral(f, -4, 4) - 1, 1)
Cs =
-3.4395e+07
Or more simply, since ‘C’ is a constant:
C = 1 - integral(f, -4, 4)
C =
-3.4395e+07
If you are using R2011b or earlier, use quad instead of integral:
C = 1 - quad(f, -4, 4)
The result is the same:
C =
-34395040.4474417
here using format long g.
Catégories
En savoir plus sur Programming dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!