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));
0 件のコメント
採用された回答
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
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
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
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.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!