Error: Inner Matrix dimensions must agree

7 次查看(过去 30 天)
INPUT:
mg=4000;
L=4;
r_min=1.2;
r_max=2.2;
r=1.2:0.05:2.2;
theta_min=-20;
theta_max=80;
theta=-20:5:80;
phi=0:9:180;
gamma=phi+20;
c_2=((r_max^2)-(r_min^2))./(cos(gamma+theta_min)-cos(gamma+theta_max));
c_1=(r_min^2)+c_2.*cos(gamma+theta_max);
a=0.5*(((c_1+c_2).^(1/2))+((c_1-c_2).^(1/2)));
b=c_2/(2*a);
F=(r*mg*L*cos(theta))/(b*a*sin(gamma+theta));
WORKSPACE:
phi: 1x21 double
r: 1x21 double
theta: 1x21 double
OUTPUT:
>> MatLab_Code_1
Error using *
Inner matrix dimensions must agree.
Error in MatLab_Code_1 (line 37)
F=(r*mg*L*cos(theta))/(b*a*sin(gamma+theta));

采纳的回答

Manoj
Manoj 2014-10-22
Try using the dot operator for b and F as well
b=c_2./(2*a);
F=(r*mg*L.*cos(theta))./(b.*a.*sin(gamma+theta));
  2 个评论
michel hardy
michel hardy 2021-5-8
heu Manjo
how i can find out when it s neccessary using .* or not? or give me suggestion for more self-study about it .
it is your favor if reply me on gmail. d.physic54
DGM
DGM 2021-5-9
An account that's been inactive for the last six years isn't likely to spring to life to answer your question.

请先登录,再进行评论。

更多回答(1 个)

Ced
Ced 2014-10-22
编辑:Ced 2014-10-22
First things first... please try to display your question in a more accessible form.
1. Use the Code {} button to insert code
2. explain what this is about, what the question is.
3. Have you tried debugging it yourself? What have you tried? What worked/didn't?
Then, to your question: "Inner matrix dimensions must agree" means that you are applying an operator to two matrices which don't match in their number of required rows/columns. Remember that matlab always does matrix operations unless stated otherwise.
Concretely in your example:
a) you probably want to do element-wise operations, e.g. compute the force for different values of r, theta, etc. You can specify element-wise operations by adding a "." to your operator, e.g. "./" instead of "/" and ".*" instead of "*".
b) If you have a number of vectors you want to combine in a formula, it may be a good idea to use linspace(a,b,N) instead of e.g. 10:5:100. That way, you'll be sure to have the same number of elements in all vectors.

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by