フィルターのクリア

Help with dot operator

5 ビュー (過去 30 日間)
Emma
Emma 2011 年 11 月 16 日
コメント済み: John D'Errico 2020 年 3 月 11 日
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
Shanuka Jayasinghe 2020 年 3 月 9 日
編集済み: Walter Roberson 2020 年 3 月 11 日
there's a table that outlines rules for the dot operator.
John D'Errico
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
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 件のコメント
Emma
Emma 2011 年 11 月 16 日
Ok, thanks. How would I solve this then? Is there no way of finding b?
Walter Roberson
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
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
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
Emma
Emma 2011 年 11 月 16 日
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)

サインインしてコメントする。


Thomas
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 件のコメント
Emma
Emma 2011 年 11 月 16 日
Thanks a lot for the help by the way! I really appreciate it.
Walter Roberson
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!

Translated by