Clear Filters
Clear Filters

Help with dot operator

5 views (last 30 days)
Emma
Emma on 16 Nov 2011
Commented: John D'Errico on 11 Mar 2020
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 Comments
Shanuka Jayasinghe
Shanuka Jayasinghe on 9 Mar 2020
Edited: Walter Roberson on 11 Mar 2020
there's a table that outlines rules for the dot operator.
John D'Errico
John D'Errico on 11 Mar 2020
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.

Sign in to comment.

Answers (3)

Walter Roberson
Walter Roberson on 16 Nov 2011
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 Comments
Emma
Emma on 16 Nov 2011
Ok, thanks. How would I solve this then? Is there no way of finding b?
Walter Roberson
Walter Roberson on 16 Nov 2011
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.

Sign in to comment.


Thomas
Thomas on 16 Nov 2011
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 Comments
Walter Roberson
Walter Roberson on 16 Nov 2011
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
Emma
Emma on 16 Nov 2011
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)

Sign in to comment.


Thomas
Thomas on 16 Nov 2011
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 Comments
Emma
Emma on 16 Nov 2011
Thanks a lot for the help by the way! I really appreciate it.
Walter Roberson
Walter Roberson on 16 Nov 2011
Sure you can just ignore the complex numbers, or filter them out:
b = b(imag(b)==0)

Sign in to comment.

Tags

No tags entered yet.

Community Treasure Hunt

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

Start Hunting!