Why do I get a complex number of this integral?
Show older comments
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
on 30 Nov 2015
0 votes
Your function "fun" is complex-valued if y < 0 because of the y^(-0.5) term.
Best wishes
Torsten.
Walter Roberson
on 30 Nov 2015
0 votes
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.
Categories
Find more on Logical 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!