In an assignment A(I) = B, the number of elements in B and I must be the same.
1 回表示 (過去 30 日間)
古いコメントを表示
at first i wrote below code to solve mechanism equations and find best parameters for my linkages
my first code:
l1=x(:,1);
l2=2;
l3=x(:,3);
l4=x(:,4);
l5=3;
l6=4;
theta1=0*pi/180;
alpha=acos((l3.^2+l5.^2-l6.^2)/(2*l3*l5)); % tha angle of coupler triangle
%%Gerashof principle %%
if l2+l3<=l1+l4;
A=1;
else
A=0;
end
R1=l1*exp(1i*theta1); %%length of 1 body
n=400; %%points
u=0; %%initial point for creating loop
for t2=0:2*pi/n:2*pi %%theta2 and step which it goes
u=u+1;
R2=l2*exp(1i*t2); %%length of 2 body
D=R1-R2; %%length of interact of 1 and 2 bodies
d=norm(D); %%mesure of interact body
tD=angle(D); %%angle of interact body wich called "D"
delta=abs(acos((l3.^2.+d.^2-l4.^2)/(2*l3*d))); %%angle between two bodies
sigma=abs(acos((l4.^2.+d.^2-l3.^2)/(2*l4*d))); %%angle between two bodies
theta3(u,1)=tD + delta;
theta2(u,1)=t2 %%tehta 2
P=A*(l2*exp(1i*t2)+l5*exp(1i*(alpha+theta3(u,1)))); %%length of distance between input and specific point
px(u,1)=real(P); %%real measure
py(u,1)=imag(P); %%imagine measure
But i encountered with this Error:
??? Error using ==> plus
Matrix dimensions must agree.
Error in ==> costFunction at 42
theta3(u,1)=tD + delta;
then i changed that to this code:
l1=x(:,1);
l2=2;
l3=x(:,3);
l4=x(:,4);
theta1=0*pi/180;
%%Gerashof principle %%
if l2+l3<=l1+l4;
A=1;
else
A=0;
end
R1=l1*exp(1i*theta1); %%length of 1 body
n=3; %%points
u=0; %%initial point for creating loop
for t2=0:2*pi/n:2*pi %%theta2 and step which it goes
u=u+1;
R2=l2*exp(1i*t2); %%length of 2 body
D=R1-R2; %%length of interact of 1 and 2 bodies
d=norm(D); %%mesure of interact body
t_D=angle(D) %%angle of interact body wich called "D"
Delta=abs(acos((l3.^2+d.^2-l4.^2)/(2*l3*d))) %%angle between two bodies
sigma=abs(acos((l4.^2+d.^2-l3.^2)/(2*l4*d))) %%angle between two bodies
tD=t_D
delta=Delta
for nn=1:n
theta3(nn)=tD+delta(nn)
end
theta2(u,1)=t2 %%theta 2
% theta3(u,1)=delta+tD %%theta3
P=A*(l2*exp(1i*t2)+l3*exp(1i*(theta3(u,1)))); %%length of distance between input and specific point
px(u,1)=real(P); %%real measure
py(u,1)=imag(P); %%imagine measure
if true
% code
end
now i encounter with this Error:
??? In an assignment A(I) = B, the number of elements in B and
I must be the same.
Error in ==> costtFunction at 41
theta3(nn)=tD+delta(nn)
i tried and read alot to solve this code but i couldn't.
would you please guide me ?
regards
4 件のコメント
Image Analyst
2017 年 1 月 2 日
x is not a function. It can't be. I don't know why you just don't say what x is.
Anyway, I made up something for x, a 30 by 4 columns array. If x has N rows then tD is an N by 1 column vector and delta is an N by N square matrix. Thus you cannot add them because they are different shapes. You need to go over the logic some more.
And you shouldn't do this:
for t2=0:2*pi/n:2*pi
You should use integers and then get the angle inside the loop. Like
theta2 = t2=0:2*pi/n:2*pi
for t2= 1 : length(theta2)
thisTheta2 = theta2(t2);
Niels
2017 年 1 月 2 日
thats exactly what i mean, use the command
keyboard
to check the size of td and delta and tell us
1.the size
2. if it has the size u wanted it to have
採用された回答
その他の回答 (2 件)
Niels
2017 年 1 月 2 日
編集済み: Niels
2017 年 1 月 2 日
i tried to run it, but i could not at that moment i asked myself what your x might be
can u tell me?
if it is a vecor why would you type
l1=x(:,1);
if it is a matrix -> here is your problem
because then your R1 is also a vector, same for D and td
thats why u cant set theta3(1,1) a vector which is supposed to be a scalar
use
keyboard
to check if i am right
replace this part of your code and run it, afterwards type l1 in the cmd window
delta=abs(acos((l3.^2.+d.^2-l4.^2)/(2*l3*d))); %%angle between two bodies
sigma=abs(acos((l4.^2.+d.^2-l3.^2)/(2*l4*d))); %%angle between two bodies
keyboard
theta3(u,1)=tD + delta;
l1
11 件のコメント
Walter Roberson
2017 年 1 月 3 日
Strictly speaking, if works the same way for vectors and scalars: it is just that the way it works tends to surprise people when it is applied to vectors or matrices.
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!