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:
question about quad2d

Subject: question about quad2d

From: dhuan Du

Date: 27 Sep, 2010 20:05:08

Message: 1 of 3

Hi:

I used quad2d to calculate my integration with v1 and h as variables. However, I still met problems. The codes and error information are given below. Could you please let me know what is the problem now?
 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
hmean=2.05968688845401; % from experiment data
hvar=1.11733636789457; % from experiment data
vmu=42*5280/3600;
theta=7*5280/3600;
alpha=0.1;
beta=0.1;
y=450;
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))/((2^0.5)*sigama))-0.416*(-(h-2.5+y*(1/v2-1/v1))/((2^0.5)*sigama))^2)))...
                *(1/((2*pi)^0.5*theta)*exp(-((v1-vmu)/theta)^2))...
                *(1/((2*pi)^0.5*theta)*exp(-((v2-vmu)/theta)^2))...
                *(1/((2*pi)^0.5*hvar*h)*exp(-((log(h)-hmean)/theta)^2));
            hmax=@(v1) 2.5+y*(1/v1-1/v2);
            eff =eff + quad2d(F,1,120*5280/3600,0,hmax);
      end

The error information:

??? Error using ==> mldivide
Matrix dimensions must agree.

Error in ==> @(v1)2.5+y*(1/v1-1/v2)


Error in ==> quad2d>tensor at 315
        top = phiTvar(x);

Error in ==> quad2d at 169
[Qsub,esub] = tensor(thetaL,thetaR,phiB,phiT);

Error in ==> Linear_Searchv1 at 46
            eff =eff + quad2d(F,1,120*5280/3600,0,hmax);
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Thanks a lot!

dhuan

Subject: question about quad2d

From: Matt Fig

Date: 27 Sep, 2010 20:34:06

Message: 2 of 3

As stated in the help for QUAD:

   "Use array operators .*, ./ and .^ in the definition of FUN
    so that it can be evaluated with a vector argument."

And the help for QUAD2D:

"All input functions must be vectorized. The function Z=fun(X,Y) must accept 2-D matrices X and Y of the same size and return a matrix Z of corresponding values. The functions ymin=c(X) and ymax=d(X) must accept matrices and return matrices of the same size with corresponding values."

Subject: question about quad2d

From: dhuan Du

Date: 27 Sep, 2010 21:35:24

Message: 3 of 3

Thanks a lot for your reply. It solved my problem. I an running my code but obtain the following a lot of warnings like below. I wonder if it is a big issue. If yes, how I can solve it.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Warning: Reached the maximum number of function evaluations (2000). The result
passes the global error test.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
"Matt Fig" <spamanon@yahoo.com> wrote in message <i7qv3u$se0$1@fred.mathworks.com>...
> As stated in the help for QUAD:
>
> "Use array operators .*, ./ and .^ in the definition of FUN
> so that it can be evaluated with a vector argument."
>
> And the help for QUAD2D:
>
> "All input functions must be vectorized. The function Z=fun(X,Y) must accept 2-D matrices X and Y of the same size and return a matrix Z of corresponding values. The functions ymin=c(X) and ymax=d(X) must accept matrices and return matrices of the same size with corresponding values."

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