Error: Inner Matrix dimensions must agree
Show older comments
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));
Accepted Answer
More Answers (1)
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.
Categories
Find more on Video Formats and Interfaces 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!