Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
help! result of quad2d is not real

Subject: help! result of quad2d is not real

From: dhuan Du

Date: 29 Sep, 2010 15:30:24

Message: 1 of 2

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) (1-0.5.*exp(-0.717.*(-(h-2.5+y.*(1./v2-1./v1)))./(sigama.*sqrt(2))-0.416.*((-(h-2.5+y.*(1./v2-1./v1)))./(sigama.*sqrt(2))).^2))...
            .*(1./(2.*pi.*theta2).^0.5.*exp(-(v1-vmu).^2./theta2))...
            .*(1./(2.*pi.*theta2).^0.5.*exp(-(v2-vmu).^2./theta2))...
            .*(1./(h*(2*pi*hvar2).^0.5).*exp(-(log(h)-hmean).^2./theta2));
        hmax=@(v1) 2.5 + y.*(1./v1-1./v2);
        eff =eff + quad2d(F,1,120*5280/3600,0,hmax);
end
+++++++++++++++++++
Error information
++++++++++++++++
eff is not real!

Subject: help! result of quad2d is not real

From: Michael Hosea

Date: 8 Oct, 2010 20:00:27

Message: 2 of 2

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)
> (1-0.5.*exp(-0.717.*(-(h-2.5+y.*(1./v2-1./v1)))./(sigama.*sqrt(2))-0.416.*((-(h-2.5+y.*(1./v2-1./v1)))./(sigama.*sqrt(2))).^2))...
>
> .*(1./(2.*pi.*theta2).^0.5.*exp(-(v1-vmu).^2./theta2))...
> .*(1./(2.*pi.*theta2).^0.5.*exp(-(v2-vmu).^2./theta2))...
> .*(1./(h*(2*pi*hvar2).^0.5).*exp(-(log(h)-hmean).^2./theta2));
> hmax=@(v1) 2.5 + y.*(1./v1-1./v2);
> eff =eff + quad2d(F,1,120*5280/3600,0,hmax);
> end
> +++++++++++++++++++
> Error information
> ++++++++++++++++
> eff is not real!

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us