Help with dot operator
조회 수: 5 (최근 30일)
이전 댓글 표시
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
Shanuka Jayasinghe
2020년 3월 9일
편집: Walter Roberson
2020년 3월 11일
there's a table that outlines rules for the dot operator.
John D'Errico
2020년 3월 11일
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
2011년 11월 16일
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
Walter Roberson
2011년 11월 16일
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.
Thomas
2011년 11월 16일
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
Walter Roberson
2011년 11월 16일
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
Thomas
2011년 11월 16일
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
Walter Roberson
2011년 11월 16일
Sure you can just ignore the complex numbers, or filter them out:
b = b(imag(b)==0)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!