Solving an equation with integral with one variable
Show older comments
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!
Accepted Answer
More Answers (1)
Star Strider
on 10 Aug 2017
Edited: Star Strider
on 10 Aug 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.
Categories
Find more on Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!