Why do I get a complex number of this integral?

12 views (last 30 days)
fun = @(y) y.^-0.5.*exp(-(y-0.01).^2./0.5);
theta = integral(fun,-Inf,Inf)
theta1 = quadgk(fun,-Inf,Inf)
theta =
1.5388 - 1.5097i
theta1 =
1.5388 - 1.5097i

Answers (2)

Torsten
Torsten on 30 Nov 2015
Your function "fun" is complex-valued if y < 0 because of the y^(-0.5) term.
Best wishes
Torsten.

Walter Roberson
Walter Roberson on 30 Nov 2015
You have y.^-0.5 as a component of the expression. When y is negative, that is going to be an imaginary value. None of the other components are imaginary so there is nothing to "cancel" the imaginary component.

Community Treasure Hunt

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

Start Hunting!