Help with dot operator

I keep getting the error code:
??? Error using ==> rdivide
Matrix dimensions must agree.
Error in ==> Design_Principles_3_MATLAB_Assignment at 41
b=Z./A
I thought that adding the dot operator would stop the error but it hasn't. Could someone please help? TThanks in advance!
My script is:
%Design_Principles_3_MATLAB_Assignment.m
%Script to find minimum peak force required from ram
%
%Emma Rhodes, 16/11/2001
%Variable Dictionary
clear all;
clc;
phi=0:5:180;
gamma=phi+20;
theta=-20:1:80;
thetamin=-20; %Minimum Theta
thetamax=80; %Maximum Theta
m=4000; %Load
mg=m*9.81;
r=1.2:0.2:2.2; %Variable Ram Length (AB)
rmin=1.2; %Retracted Ram Length (AB)
rmax=2.2; %Extended Ram Length (AB)
L=4; %Boom Length (OC)
c2=((rmax^2)-(rmin^2))./((cos(gamma+thetamin))-(cos(gamma+thetamax)))
c1=(rmax^2)+(c2.*(cos(gamma+thetamax)))
C_minus=c1-c2
X=C_minus(C_minus>0)
C_plus=c1+c2
Y=C_plus(C_plus>0)
Z=c2(c2>0)
a=(((Y).^(1/2))+((X).^(1/2)))/2
A=2.*a
b=Z./A

2 个评论

By the way, your next anxious question will be why do I get the wrong answers?
cos and sin (along with the other trig functions) use radians, NOT degrees. However, your variables appear to be in degrees. S you will get what you consider to be strange results.
If you insist on the use of degrees, then you must alsu use sind and cosd. Or, you could convert the arguments to to radians from degrees. Take your pick.

请先登录,再进行评论。

回答(3 个)

Walter Roberson
Walter Roberson 2011-11-16

0 个投票

There is no "dot operator". "./" is a single operator whose name is two characters long, not a dot operator applied to the "/" operator.
When you use "./" then the size of the left side must be exactly the same as the size of the right side, unless the right side is a scalar.

2 个评论

Ok, thanks. How would I solve this then? Is there no way of finding b?
I do not know what your code is intended to do, so I do not know whether there is any way of finding b.
Sometimes it is easier to do the calculation on the entire array, including locations it will not produce meaningful answers for, and then filter out the locations that would be meaningless.

请先登录,再进行评论。

In your case Z=[1x19] and A=[1x23], both the matrices are of different dimensions and hence you get a dimension mismatch error..
Also Emma, are you sure your equation are correct:
The code works correctly if:
Z=c1(c1>0)
Just check your equations again..

2 个评论

Note: that is the link for rdivide for the fixed point toolbox. The general reference is http://www.mathworks.com/help/techdoc/ref/ldivide.html which covers both ldivide and rdivide
I am basically trying to find a and b using these equations and they are definitely right. If I don't use only the positive answers for c1-c2 and c1+c2 then I get complex numbers for a
c2=((rmax^2)-(rmin^2))./((cos(gamma+thetamin))-(cos(gamma+thetamax)));
c1=(rmax^2)+(c2.*(cos(gamma+thetamax)));
a=(((c1+c2).^(1/2))+((c1-c2).^(1/2)))./2
b=c2./(2.*a)

请先登录,再进行评论。

hmm,, this code works fine now:
%Design_Principles_3_MATLAB_Assignment.m
%Script to find minimum peak force required from ram
%
%Emma Rhodes, 16/11/2001
%Variable Dictionary
clear all;
clc;
phi=0:5:180;
gamma=phi+20;
theta=-20:1:80;
thetamin=-20; %Minimum Theta
thetamax=80; %Maximum Theta
m=4000; %Load
mg=m*9.81;
r=1.2:0.2:2.2; %Variable Ram Length (AB)
rmin=1.2; %Retracted Ram Length (AB)
rmax=2.2; %Extended Ram Length (AB)
L=4; %Boom Length (OC)
c2=((rmax^2)-(rmin^2))./((cos(gamma+thetamin))-(cos(gamma+thetamax)))
c1=(rmax^2)+(c2.*(cos(gamma+thetamax)))
% C_minus=c1-c2
% X=C_minus(C_minus>0)
% C_plus=c1+c2
% Y=C_plus(C_plus>0)
% Z=c2(c2>0)
a=(((c1+c2).^(1/2))+((c1-c2).^(1/2)))./2
A=2.*a
b=c2./(2.*a)

3 个评论

Yea, but some of the answers are complex still. Do I just ignore those?
My main aim is to find the minimum peak force required from the ram in a crane by optimising the geometry and using:
F=(r./(b*a))*m*g*L*((cos(theta))/(sin(gamma+theta)))
Thanks a lot for the help by the way! I really appreciate it.
Sure you can just ignore the complex numbers, or filter them out:
b = b(imag(b)==0)

请先登录,再进行评论。

标签

尚未输入任何标签。

提问:

2011-11-16

Community Treasure Hunt

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

Start Hunting!

Translated by