Trouble by function handling: "Inner matrix dimensions must agree."
1 view (last 30 days)
Show older comments
Hi,
I would like to define one function with 2 variables, then to integrate it. As it is a long expression, I divided it into other functions.
C=etar*etap*Pp/(h*c/lambdap)*2*alpha/(pi*wp^2);
Rp=@(r,z)C*exp(-2*r*r/(wp*wp))*exp(-alpha*z);
zR=pi*w0^2/lambda;
w=@(z)w0*sqrt(1+(z/zR)^2);
Ne=@(r,z)Rp(r,z)*Tau;
Ng=@(r,z)Nt-Rp(r,z)*Tau;
BetaS=@(r,z)(Ne(r,z)-Ng(r,z))/(Ne(r,z)+Ng(r,z));
integrd1=@(r,z)BetaS(r,z)*exp(-2*r*r/(w(z)*w(z)))*r;
integrd2=@(r,z)exp(-2*r*r/(w(z)*w(z)))*r;
BetaSAv=dblquad(integrd1,0,Inf,0,lc)/dblquad(integrd2,0,Inf,0,lc);
All the constants are defined before. I have then the error message:
??? Error using ==> mtimes
Inner matrix dimensions must agree.
Error in ==> BetaSAvCalc2>@(r,z)C*exp(-2*r*r/(wp*wp))*exp(-alpha*z) at 28
Rp=@(r,z)C*exp(-2*r*r/(wp*wp))*exp(-alpha*z);
The error message continue with all lines which have a failure. Could you please help me to understand what is wrong ? Thanks in advance !
0 Comments
Accepted Answer
Walter Roberson
on 9 Aug 2011
You get that message when you try to use "*" to multiply two matrices and the second dimension of the first matrix does not match the first dimension of the second matrix. That is, "*" means "matrix multiplication".
Probably somewhere in your expression is a vector. You might be thinking you are squaring each element of the vector by multiply the vector by itself, but since "*" is matrix multiplication instead you get an error.
Convert your "*" in to ".*" and convert your "/" in to "./" except for the cases where you are sure that you want matrix multiplication (in the mathematical sense.)
0 Comments
More Answers (1)
Anne-Laure
on 9 Aug 2011
1 Comment
Walter Roberson
on 9 Aug 2011
dblquad() passes a vector as the first argument and a scalar as the second.
See Also
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!