All I get is
??? Undefined function or variable 'y'.
If I define y to be 1, I get a real result, y = 100 or a complex input,
I get complex. Since you are surprised to get a complex result, I doubt
you have y set to a complex number, so my first guess is that it is
negative and that hmax is sometimes negative. Then the log(h) in F will
give a complex result, and the result will remain complex.

Mike
dhuan Du wrote:
> Hi buddy:
>
> Could anybody tell me why my integral result calcualted by the code
> below is a complex number ( with the format like 3+4i) instead of a real
> number ? It is supposed to be real number.
> +++++code++++++++++++++++++++++++++++++++++++++
> eff=0;
> saf=0;
> sigama=0.5832;
> hmean=2.05968688845401; hvar2=1.11733636789457; vmu=42*5280/3600;
> theta2=49*5280/3600;
>
> for v=1:1:120
> v2=v*5280/3600;
> F=@(v1,h)
> (10.5.*exp(0.717.*((h2.5+y.*(1./v21./v1)))./(sigama.*sqrt(2))0.416.*(((h2.5+y.*(1./v21./v1)))./(sigama.*sqrt(2))).^2))...
>
> .*(1./(2.*pi.*theta2).^0.5.*exp((v1vmu).^2./theta2))...
> .*(1./(2.*pi.*theta2).^0.5.*exp((v2vmu).^2./theta2))...
> .*(1./(h*(2*pi*hvar2).^0.5).*exp((log(h)hmean).^2./theta2));
> hmax=@(v1) 2.5 + y.*(1./v11./v2);
> eff =eff + quad2d(F,1,120*5280/3600,0,hmax);
> end
> +++++++++++++++++++
> Error information
> ++++++++++++++++
> eff is not real!
